I am building a custom WordPress theme and am having issue with linking to my CSS. Using <?php get_template_part( 'template-parts/template-header' ) ?>
at the top of all of my templates (such as my homepage, which lives at template-parts/template-homepage
, I am grabbing the header I have built. In the head of my header HTML I have <link rel="stylesheet" href="homepage.css"/>
.
To ensure it’s not something like a relative path issue, I’ve also placed my css files within template parts. When I preview the page my HTML is there, but no CSS. Any thoughts as to why this might be?
Advertisement
Answer
You hardly posted any code, so it’s impossible to give you clear instructions, but in general, you should enqueue all style sheets in your functions.php
file, using the wp_enqueue_style()
function.
Here are links to two pages which tell you more about this:
1.) A more technical description: https://developer.wordpress.org/reference/functions/wp_enqueue_style/
2.) A more tutorial-like description: https://learn.wordpress.org/lesson-plan/enqueueing-scripts-and-styles/