0

I created a Twenty Fifteen child theme and wondering what is the best method to add style sheets into the child theme? Should I use enqueue script in functions.php, or add directly in header.php?

2

Firstly, never add the stylesheet on header.php unless you have to. It is not the WordPress convention.

Secondly, adding stylesheet to header.php will cause certain problem like dependency hierarchy. Cause when you install any plugin and if it has its stylesheet then the dependency hierarchy is automatically managed by WordPress system by wp_enqueue_scripts hook.

Thirdly, by using wp_enqueue_scripts hook you can use WordPress default scripts and stylesheets which is kinda messy if you proceed to use it in the header.

Fourthly, (I'm not 100% sure) caching can be a problem if you use stylesheet on header.php.

And all those rule are applicable for themes as well as child themes and plugins.

  • If you think this answer clarified your concept, then it would be great if you accept the answer. @sam – CodeMascot Aug 20 '16 at 19:07
  • sure, i am just reading the answer at the moment and just a small confusion left now , my HTML template have stylesheets linked in header sections which i have pasted into my header.php and added wp_head() below . So am i supposed to remove my stylesheets links from the header section and add it using enqueue script ? or am i not supposed to copy paste my HTML template header into my header.php which i want in all WordPress pages ? – sam Aug 20 '16 at 19:15
  • Obviously you should add those scripts and stylesheets using enqueue script. Never put your scripts and stylesheet on any template or part of any template files unless you must have to. – CodeMascot Aug 20 '16 at 19:19

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.