Your templates are being used incorrectly. You should not be starting and ending a complete HTML document in each of these files.
Template Hierarchy
WordPress will compose a page for you by using the sub-templates header.php
at the top, footer.php
at the bottom, and with the appropriate template in between. Very important to note the template hierarchy in WordPress. Different template parts will be called for based on which view is being rendered. Any good theme has a variety of templates for different contexts and purposes. Read: https://developer.wordpress.org/themes/basics/template-hierarchy/.
Example
Your blog will be rendered like this:
header.php
index.php
footer.php
A single blog post will use this:
header.php
single.php
footer.php
A page will use this:
header.php
page.php
footer.php
etc…
Theming
A good idea is to take a look at the contents of these files in a default WordPress theme, note how the document is started in header.php, and is closed in footer.php. Follow this and your stylesheet will be enqueued as expected. More reading on themes: https://developer.wordpress.org/themes/getting-started/what-is-a-theme/
The stylesheet URI you are enqueueing in functions.php
, doesn’t look complete to me. This bit:
get_stylesheet_uri()
This will just get the directory of the of the stylesheet, which is usually the root directory of the theme. You need to point to the specific stylesheet, so your function would look like this:
function load_css(){
wp_enqueue_style('styles', get_stylesheet_uri() . '/style.css' );
}
add_action('wp_enqueue_scripts', 'load_css');
…where . '/styles.css'
is completing the path to the stylesheet file. Make sure the file name matches.
Resource: https://developer.wordpress.org/reference/functions/get_stylesheet_uri/
Sorry I didnt see notice that the first time My other answer still applies for the templating issues I saw the first time.
The problem was that I didn’t include the header on index.php
<?php
get_header();
?>
I added this on the first line of index.php, removing the opening and tags and it started working.
SOLUTION
The problem was that I didn’t include the header on index.php
<?php
get_header();
?>
I added this on the first line of index.php, removing the opening and tags and it started working.
ORIGINAL POST
I know this has been posted about already, but none of the solutions I try seem to be working.
I am trying to load a stylesheet for my wordpress theme, but it doesn’t seem to be working. My stylesheet is named style.css
and it resides in the root folder (the theme folder), alongside index.php
, header.php
, footer.php
and functions.php
.
Edit: Using the firefox debugger shows that the stylesheet is definitely not loading. The style editor section gives me a, “This page has no stylesheet.”
Here are the contents of those files:
index.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="style.css"/>
</head>
<body>
</body>
</html>
style.css
body{
background-color: green;
background: green;
}
header.php
<!DOCTYPE html>
<html>
<head>
<?php wp_head();?>
</head>
</html>
footer.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
<footer class="site-footer"></footer>
<?php wp_footer(); ?>
</body>
</html>
functions.php
<?php
function load_css(){
wp_enqueue_style('styles',get_stylesheet_uri());
}
add_action('wp_enqueue_scripts', 'load_css');
?>
@clota974 Still nothing unfortunately.
Thanks for the suggestion. I looked through the link and I made the changes (header.php starts the and
tags and stops after wp_head() with the tag still open, index.php closes the tag and starts the tag, and footer.php closes the and tags), but still nothing.
From what I understand, get_stylesheet_uri() defaults the search to “style.css” in the root folder. I still tried it though, with no luck unfortunately.