I´m creating a child theme for Twenty Twelve v1.0 and I want to remove the Open Sans font.

Open Sans is added in Twenty Twelve´s functions.php:

wp_enqueue_style( 'twentytwelve-fonts', add_query_arg( $query_args, "$protocol://fonts.googleapis.com/css" ), array(), null );

I´ve tried to deregister/dequeue the stylesheet in my childtheme´s functions.php (see examples below) but to no effect:

function example_scripts_styles() {     
    wp_deregister_style( 'twentytwelve-fonts' );    
    wp_dequeue_style( 'twentytwelve-fonts' );
}
add_action( 'wp_enqueue_scripts', 'example_scripts_styles' );

Any ideas how I can remove this file?
Thanks!

4

Found the answer here:

Script dequeuing calls should be added to the wp_print_scripts action
hook(..). This is because scripts are typically enqueued on the
wp_enqueue_script hook, which happens early in the wp_head process.
The wp_print_scripts hook happens right before scripts are printed,
and thus is latest in the process. (Otto)

Following the same logic we can use wp_print_styles to remove the Open Sans font:

function remove_open_sans() {
   wp_dequeue_style( 'twentytwelve-fonts' );
}
add_action('wp_print_styles','remove_open_sans');

This did the trick.

Leave a Reply

Your email address will not be published. Required fields are marked *