Scott Hunter Scott Hunter - 4 months ago 10
Javascript Question

Error in Function to add Google Fonts in WordPress Theme

I have the following function in my Wordpress themes functions file which should add google fonts to the theme. The problem is that i am getting the following error.

Parse error: syntax error, unexpected '=', expecting ')' in /home/***/wp-content/themes/sienna/functions.php on line 382


Anyone know how I can fix this please ?

Heres the function

// Add Google Fonts
function sienna_fonts_url() {
$fonts_url = '';
$font_families = array();
$font_families[] = 'Questrial';
$font_families[] = 'Open Sans:400,600,700';
$font_families[] = 'Playfair Display:400,700';

$query_args = array(
'family' => urlencode( implode( '|', $font_families ) ),
'subset' => urlencode( 'latin,latin-ext' ),
);

$fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
}

return esc_url_raw( $fonts_url );
}


Many thanks,

Scott.

Answer

There you go:

function sienna_fonts_url() {
$fonts_url = '';
$font_families = array();
$font_families[] = 'Questrial';
$font_families[] = 'Open Sans:400,600,700';
$font_families[] = 'Playfair Display:400,700';
$query_args = array(
    'family' => urlencode( implode( '|', $font_families ) ),
    'subset' => urlencode( 'latin,latin-ext' ),
);
$fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
return esc_url_raw( $fonts_url );

}