0

Given this script:

function register_styles(){
    wp_register_style('google-fonts', '//fonts.googleapis.com/css?family=Oswald|Open+Sans');
    wp_register_style('bootstrap', get_template_directory_uri() . '/css/bootstrap.min.css', array('google-fonts'));
    wp_register_style('font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css', array('bootstrap'));
}
add_action('init', 'register_styles');

function enqueue_styles(){
    wp_enqueue_style('font-awesome');
}
add_action('wp_enqueue_scripts', 'enqueue_styles');

Styles are rendered correctly, but I get only one dns-prefetch link:

<link rel='dns-prefetch' href='//maxcdn.bootstrapcdn.com' />

Instead, since font-awesome depends on bootstrap that in turn depends on google-fonts, I'd expect a dns-prefetch for Google Fonts too, like this:

<link rel='dns-prefetch' href='//fonts.googleapis.com' />
<link rel='dns-prefetch' href='//maxcdn.bootstrapcdn.com' />

Is this a Wordpress bug? I'm using version 4.6.1

1 Answer 1

1

Since WP 4.6 prefetch dependencies are only generated when styles are enqueued, not when they are only registered. Since you are only enqueueing Font Awesome, that is the only prefetch link you get. If you enqueue all style files properly, your problem should be solved.

1
  • Thank you a lot! I'm a WordPress newbie, sorry for the dumb questions
    – Ivan
    Nov 22, 2016 at 21:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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