I am totally new to WordPress and developing my own theme but function.php is not loading CSS file.


        <?php wp_head(); ?>            
        <h2>I'm header.php</h2>


while (have_posts()) {
    <h2><?php the_title(); ?></h2>
    <?php the_content(); ?>

<?php }



function main_css() {
    wp_enqueue_style('style', get_stylesheet_uri() );
add_action( 'wp_enqueue_scripts', 'main_css' );


Theme Name: My Theme
Author: Tesla
Version: 1.0    
    color: green;
    color: pink;

I have tried many ways but it's not loading even disable the browser cookies, hard refresh, reinstall the Wordpress.

Whats wrong with my code?

  • I have added <link rel='stylesheet' id='my-theme' href='<?php echo get_template_directory_uri(); ?>/style.css' type='text/css' media='all' /> and its workd fine but I think this is not a proper way to inlcude the CSS and JS files. May 14, 2018 at 17:12

2 Answers 2


The theme functions file name must be called functions.php not function.php. This can cause your code to not implement? You must check carefully.

  • Thanks a lot, @Mr.Optical. It works. I have been searching the solution for 2 days. May 14, 2018 at 17:23
  • @PollyTearesa you’re welcome :) May 14, 2018 at 17:49

As was mentioned by Mr. Optical and Mat, the name of your functions files needs to be functions.php.

I think it's great that you're looking to learn how to code a WordPress Theme. One thing I recommend for aspiring theme developers is downloading the Underscores Starter Theme which is maintained by the team at Automattic.

This will give you the foundation that you can use for your theme or it can serve as a reference to learn from.

I also recommend book marking the WordPress Theme Developer Handbook. There, you'll get valuable information on how to properly develop a WordPress Theme.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.