auto
auto

Reputation: 1173

Wordpress enqueue function is not being called from functions.php; stylesheet not added

I am building my first wordpress theme and am trying to enqueue an external style.css file.

The file is located in the theme's main directory.

I have created a functions.php file and have added the following code into:

<?php

function addExternalStuff(){
    wp_enqueue_style('style', get_stylesheet_uri());

}  
add_action('wp_enqueue_scripts','addExternalStuff');  

This is exactly what tutorials and documentation says to add.

I've also used wp_enqueue_style in add_action().

<?php

function addExternalStuff(){
    wp_enqueue_style('style', get_stylesheet_uri());

}  
add_action('wp_enqueue_style','addExternalStuff'); 

Nothing happens. The stylesheet is not added to the code. I've added an echo as well at the top of the function, and it is not printed. I have also added an echo at the very top of functions.php, outside the addExternalStuff() function and it prints, meaning this is the correction functions.php file.

Upvotes: 0

Views: 899

Answers (1)

auto
auto

Reputation: 1173

After some digging, I learned that I did not include wp_head() in the header of my header.php file. This is how Wordpress adds the stylesheet to the header and enqueue can't without it (also wp_footer in footer.php).

In header.php:

<head>

     <?php wp_head() ?>

</head>

In functions.php also used get_template_directory_uri() instead of get_stylesheet_uri() so that I could call a stylesheet with a unique name other than the default style.css.

  <?php

    function addExternalStuff(){
        wp_enqueue_style('style',get_template_directory_uri().'css/new_stylesheet.css');

    }  
    add_action('wp_enqueue_scripts','addExternalStuff'); 

Upvotes: 3

Related Questions