0

I just want to add one extra line (a third-party font stylesheet) to the header of my blog. I have a child theme set up, but at the moment it only has a custom stylesheet, style.css.

Very simply, how can I do this?

All the answers I can find seem to suggest that I create multiple long and complicated files that replicate a lot of parent theme code. Surely there must be a simple way?

If I create a new header.php with just one line (the extra stylesheet), as per this answer, that file overwrites all of <head>.

If I add a simple functions.php file like this answer suggests, it just inserts raw code into the page.

Is there any way I can just insert one line into the header without having to replicate all the header PHP code? Surely it can't be this hard.

0

You simply enqueue your stylesheet using the get_stylesheet_uri()

function my_scripts() {
    // enqueue style
    wp_enqueue_style('name-of-my-script', 'https://cloud.typography.com/6718632/6718632/css/fonts.css');
}
add_action('wp_enqueue_scripts', 'my_scripts');
  • Thanks. What should I call the file in which I do this? – Richard Apr 12 '18 at 23:54
  • It's an external stylesheet: https://cloud.typography.com/6718632/6718632/css/fonts.css. Should I replace /style-sheet.css in the above with this URL? – Richard Apr 12 '18 at 23:55
  • And is name-of-my-script significant in some way, or can I leave that string as it is? – Richard Apr 12 '18 at 23:56
  • I think from Googling - this file ought to be called functions.php and it ought to have enclosing PHP tags - is that right? – Richard Apr 12 '18 at 23:58
  • this would be placed in your functions.php file, name-of-my-script can be changed to anything. It is used to ensure the style is not loaded twice – James Apr 12 '18 at 23:59

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.