Remove open sans font link from wordpress head

How do I go about removing the open sans font link from WordPress’s header without using a plugin?

I’m currently using twentyfifteen theme and I was using Disable Google Fonts plugin but I’m trying to cut down on plugins.

Related posts

2 comments

  1. You need to dequeue_style with an additional priority call:

    function wpso_dequeue_google_fonts() {
        wp_dequeue_style( 'twentyfifteen-fonts' );
    }
    add_action( 'wp_enqueue_scripts', 'wpso_dequeue_google_fonts', 20 );
    

    See https://codex.wordpress.org/Function_Reference/wp_dequeue_style

    Use this function in a child theme, because if you edit the original twentyfifteen theme, your changes will get overwritten with one of WP’s peridodic theme updates. See Child Themes « WordPress Codex

    And then remove any calls for Open Sans from font-family: rule in the stylesheet.

  2. Add this to your functions.php file of your child theme.

    function remove_open_sans() {
       wp_dequeue_style( 'twentyfifteen-fonts' );
    }
    add_action('wp_enqueue_scripts','remove_open_sans');
    

    The Google fonts are being added like this:

    wp_enqueue_style( 'twentyfifteen-fonts', twentyfifteen_fonts_url(), array(), null );
    

    So you need to dequeue the styles like they are added.

Comments are closed.