I'm writing a theme where I'd like to give users the ability, via a theme option, to specify a typeface for their site with Google Web Fonts.
If a user wants to embed a font like, say, News Cycle, then the code needs to specify this in two places, in a <link>
tag within the <head>
, and in the site's CSS.
In the <link>
tag, the font is specified with a +
(plus sign) in the name:
<link href='http://fonts.googleapis.com/css?family=News+Cycle' rel='stylesheet' type='text/css'>
However, in the CSS, there is no plus sign:
h1 { font-family: 'News Cycle', arial, serif; }
Ideally I'd like users to just write or paste the name of the font into a form field, and then, in the code, to replace spaces with plus signs where needed.
From googling around, I think this can be done with str_replace
or another similar bit of PHP, but I'm a PHP novice. Can anyone shed some light on the best way to do this?
At the moment the relevant PHP in my header.php looks a bit like this:
<?php
$options = get_option('mytheme_theme_options');
if( isset( $options['webfont'] ) && ( !empty( $options['webfont'] ) ) )
printf( "WEBFONT LINK", $options['webfont'] );
?>
Thanks.