0

I'm brand new at theme development. My css stylesheet is not loading, and I'm not sure if the problem is in the functions.php, style.css, index.php, header.php, or footer.php file. I've added a div class "post-title" in index.php, which should change the font color of my posts, but right now it's not doing that. My code is below:

functions.php:

            <?php
                function link_css_stylesheet() {
                    wp_enqueue_style('style', get_stylesheet_uri());
                }

                add_action('wp_enqueue_scripts', 'link_css_stylesheet');
            ?>

style.css:

            /*
            Theme Name: Richard Theme Name
            Theme URI: http://www.intechio.com/themes/Richard-Theme
            Author: Richard
            Author URI: https://intechio.com
            Description: Theme project.  
            Version: 1.0
            */

            .post-title {
                color : rgb(0,100,0);
            }

index.php:

            <?php
                get_header();
                ?>

                <div class="post-title">

                    <?php

                    if (have_posts()) : 
                        while (have_posts()) : the_post();
                            the_title();
                            the_excerpt();
                        endwhile; 
                    else: 
                        echo "No posts.";
                    endif;

                    ?>

                </div>

                <?php
                get_footer();
            ?>

header.php:

            <!DOCTYPE html>
                <html>
                    <head>
                        <meta charset=”<?php bloginfo(‘charset’); ?>
                        <title><?php wp_title(); ?> | <?php bloginfo('name'); ?></title>
                        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
                        <?php wp_head(); ?>
                    </head>
                        <body <?php body_class(); ?>>
                            <h1><?php bloginfo(‘name’); ?></h1>
                            <h2><?php bloginfo(‘description’); ?></h2>

footer.php:

            <p>this is a footer</p>
            </body>
            </html>

Thank you in advance for any tips you might be able to offer.

  • Check the resulting HTML source to see what get_stylesheet_uri() return in functions.php. – Max Yudin May 21 '18 at 11:04
0

I have tried to create WordPress theme using your functions.php, style.css and index.php and for me, the stylesheet is loading correctly. Please make sure you have added your header.php and footer.php for the theme. Please study some tutorials for theme development on WordPress.You can look at this link https://codex.wordpress.org/Theme_Development for detailed information.

  • Thanks, maybe the problem is in the header or footer files. I've edited my question above to add the header and footer code. If possible, please take a glance and let me know if anything looks obviously wrong with the code. – dimery2006 Nov 4 '17 at 21:24
  • Can you please post the HTML for your home page (view source) - you may need to use pastebin or a similar service. – Alexander Holsgrove Nov 4 '17 at 21:41
  • Alex Holsgrove, the css style has suddenly updated the font color. But the really strange thing is that there seems to be a time delay. I changed the rgb color from (0,100,0) to (255,0,0) in my style.css, but now when I load the page in another tab and use inspect element, the old rgb value (0,100,0) still shows. Maybe I need to create a new thread for this odd behavior. – dimery2006 Nov 5 '17 at 0:54
0

It's likely that your header.php file doesn't include:

<?php wp_head(); ?> 

This function will add the HTML markup to include your CSS file.

  • I do have the wp_head() function in my header.php file, but maybe there's some other problem. I've edited my question above to include my header/footer code. Thanks. – dimery2006 Nov 4 '17 at 21:25
0

It turns out there was nothing wrong with my code. The problem lies in the browser (Chrome) not refreshing the css styles. I initially thought the stylesheet was not loading, but in fact the browser was simply needing a refresh. The solution is to force a cache refresh by typing Ctrl + F5. Thanks to all of you for the help!

0

I have created a simple WordPress theme using your codes and i see that your style is working correctly.

But there is some syntax issue in header.php file.

 <meta charset="<?php bloginfo('charset'); ?>

You have missed a > to close meta tag and a " to close charset. Correct one is:

 <meta charset="<?php bloginfo('charset'); ?> ">

Also in order to avoid further issues, please check WordPress theme development documentations.

Just as a quick guides, You need to use wp_footer() function in footer.php.

Also avoid using ?> at the end of file. because any character after it will cause headers already sent error and you may see only a blank page.

0

wp_enqueue_style('style', get_stylesheet_uri());

Does not return style.css

It returns the theme folder.

Try something like this:

function link_css_stylesheet() {
    wp_enqueue_style('style', get_bloginfo('template_directory').'/style.css');
}
add_action('wp_head', 'link_css_stylesheet');

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.