0

I'm making a child theme, and I'd like to remove the Google font style that it calls for in 'fonts-style'

function nada_theme_styles() { 
    wp_register_style( 'fonts-style', '//fonts.googleapis.com/css?family=Roboto:300,700', array(), null, null );
  wp_register_style( 'nada-style', get_stylesheet_uri() );

  wp_enqueue_style( 'fonts-style' );    
  wp_enqueue_style( 'nada-style' );    
}
add_action('wp_enqueue_scripts', 'nada_theme_styles');

I currently have this:

function remove_nada_theme_font_style() {
    wp_deregister_style( 'fonts-style' );
    wp_dequeue_style( 'fonts-style' );
}
add_action( 'wp_enqueue_scripts', 'remove_nada_theme_font_style' );

I've tried that as well as adding my action to wp_print_scripts and styles, and changing the priority.

I've referenced similar threads here, and I'm not sure what I'm missing. Thanks for your help!

  • 1
    Adding a priority of 11 or any bigger number should work. – Pieter Goosen Mar 10 '16 at 6:17
1

It is pretty simple:

function remove_nada_theme_font_style() {
    remove_action( 'wp_enqueue_scripts', 'nada_theme_styles' );
}

add_action( 'after_setup_theme', 'remove_nada_theme_font_style' );

Since the child theme is loaded before the parent theme, you can't simply remove the action. because the add_action calls in the parent theme will simply overwrite your requests. You have to wrap it into the after_setup_theme hook. This hook will fire after the child and parent theme is loaded. So all removing filters and actions from the parent theme should go there.

Source: http://code.tutsplus.com/articles/how-to-modify-the-parent-theme-behavior-within-the-child-theme--wp-31006

edit

This will remove the whole styles and not just the font scripts.

If you just want to deregister the font:

function remove_nada_theme_font_style() {
    wp_dequeue_style( 'fonts-style' );
    wp_deregister_style( 'fonts-style' );
}

add_action( 'after_setup_theme', 'remove_nada_theme_font_style' );
| improve this answer | |
  • 1
    but that will remove both css files when they only want one removed. – Milo Mar 10 '16 at 6:42
  • Good point... I will edit it accordingly – iantsch Mar 10 '16 at 6:44
  • Thanks! I didn't know about after_setup_theme... Though it's still not working, the font is still there. Not sure what else I'm missing. – Gedaly Mar 11 '16 at 7:20
  • Nevermind, I fixed it! Just deregistering the font didn't seem to work, but I was able to use your first solution to remove the whole action, and then registered my own stylesheet in another function where I also registered my own google fonts. Thank you! – Gedaly Mar 11 '16 at 7:32
  • have you tried adding a higher priority number, as @Pieter Goosen suggested? – iantsch Mar 11 '16 at 18:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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