I’m using an echo tag to output a few font properties chosen by a user on my site, through WordPress > Appreances > Theme Options.
Once they have selected the font that they like from one of the select menus on this page, it gets called into the source code for the front-end to display like so:
header.php
<style>
<?php $typography = of_get_option('main-text');
if ($typography) {
echo 'p {
font: ' . $typography['size']. ' '.$typography['face'] . ';
font-style: ' . $typography['style'] . ';
color: '.$typography['color'].';
}';
$typography = str_replace(' ','+',$typography);
}
?>
</style>
As the choices they have in the select menu include Google Web Fonts, some of the font faces contain + symbols which I would like to replace with a simple space instead.
As I’m a little unfamiliar with PHP, I was wondering how would I correctly write out something like
$typography = str_replace(' ','+',$typography);
for the above script, as what I’ve tried/where I’ve placed this, isn’t working.
Thank you.
Your first 2 parameters of the str_replace function are backwards. Also if you want it to replace before echoing out, then you would have to do the replace, well, before echoing it out.
If you only need the replace done for the ‘face’ key, then you could do: