Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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!

share|improve this question
    
+1 no close vote. Perfectly valid question. –  kaiser Sep 28 '12 at 12:55

4 Answers 4

up vote 10 down vote accepted

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.

share|improve this answer

In the functions.php of Twenty Twelve v1.1, a comment explains how to remove the stylesheet from the wp_enqueue_scripts hook:

function mytheme_dequeue_fonts() {
         wp_dequeue_style( 'twentytwelve-fonts' );
      }

add_action( 'wp_enqueue_scripts', 'mytheme_dequeue_fonts', 11 );

Your attempt that didn't work was missing the priority parameter in the add_action(). The parent theme enqueues the style with the default priority of 10, so the child theme has to dequeue it with priority 11.

share|improve this answer

You'll find that WordPress itself also loads Open Sans (at least version 3.8). In fact, it was loading Open Sans three times for me: one for the WP admin, one for the TinyMCE editor, and another for the page.

If your goal is removing Open Sans altogether, you'll have to hack WordPress itself (or stay with an older version).

My own code to remove the Open Sans (at least when a user isn't logged in, which is most of the time) is my theme's functions.php:

add_action( 'wp_enqueue_scripts', 'ays_setup', 9 );

function ays_setup() {

    /* no Open Sans font in TinyMCE */
    remove_filter( 'mce_css', 'twentytwelve_mce_css' );

    /* no Open Sans font for the page */
    remove_action( 'wp_enqueue_scripts', 'twentytwelve_scripts_styles' );
    add_action( 'wp_enqueue_scripts', 'ays_scripts_styles' );
}

function ays_scripts_styles() {
    global $wp_styles;

    /*
     * Adds JavaScript to pages with the comment form to support
     * sites with threaded comments (when in use).
     */
    if ( is_singular() && comments_open() && get_option( 'thread_comments' ) )
        wp_enqueue_script( 'comment-reply' );

    // Adds JavaScript for handling the navigation menu hide-and-show behavior.
    wp_enqueue_script( 'twentytwelve-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '1.0', true );

    // Loads our main stylesheet.
    wp_enqueue_style( 'twentytwelve-style', get_stylesheet_uri() );

    // Loads the Internet Explorer specific stylesheet.
    wp_enqueue_style( 'twentytwelve-ie', get_template_directory_uri() . '/css/ie.css', array( 'twentytwelve-style' ), '20121010' );
    $wp_styles->add_data( 'twentytwelve-ie', 'conditional', 'lt IE 9' );
}

twentytwelve_scripts_styles has everything in twentytwelve_scripts_styles except the bit that loads Open Sans.

share|improve this answer

On WP 3.8+, I sucessfully removed 'Open Sans' from my frontend styles using thetrickster's gist:

<?php
// Remove Open Sans that WP adds from frontend
if (!function_exists('remove_wp_open_sans')) :
    function remove_wp_open_sans() {
        wp_deregister_style( 'open-sans' );
        wp_register_style( 'open-sans', false );
    }
    add_action('wp_enqueue_scripts', 'remove_wp_open_sans');

    // Uncomment below to remove from admin
    // add_action('admin_enqueue_scripts', 'remove_wp_open_sans');
endif;
?>

'Open Sans' can be a plugin dependancy.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.