Jump to content

Wordpress enqueue styles

Go to solution Solved by ladybug,
On 3/5/2022 at 8:49 PM, stefanmz said:

oh yeah I did wrap it in php tags. Thanks! We'll see if it works now.

 

UPDATE: Well it doesn't. I called the function and same thing no styles,when I view page source I don't see any link tags generated. Is my enqueue code wrong? Also it says undefined function wp_head. 

It works I had to use get_template_directory_uri instead of get_template_directory

Hello, I am trying to enqueue my styles in Wordpress based on instructions here https://developer.wordpress.org/themes/basics/including-css-javascript/   .However it is very confusing and not very well written so can you clarify?

First, this functions.php do I have to create that file in my theme root folder where the header.php, footer.php, index.php and the other files are or are they talking about the functions.php that's already there in wp-includes and I need to edit it? 

Second, does that look like it will work(the code which has to be written  in functions.php):

function add_styles(){
    wp_enqueue_style('stylesheet', get_template_directory() . '/css/stylesheet.css' );
   ....
}
add_action( 'wp_enqueue_styles', 'add_styles' );

And third, after enqueueing the sale like that do I still need to add those stylesheets in the header.php or should I delete the lines where I do that afterwards from header.php and just leave the enqueue function in functions.php?

Link to comment
https://linustechtips.com/topic/1416123-wordpress-enqueue-styles/
Share on other sites

Link to post
Share on other sites

48 minutes ago, stefanmz said:

First, this functions.php do I have to create that file in my theme root folder where the header.php, footer.php, index.php and the other files are

Yes

 

49 minutes ago, stefanmz said:

And third, after enqueueing the sale like that do I still need to add those stylesheets in the header.php or should I delete the lines where I do that afterwards from header.php and just leave the enqueue function in functions.php?

Yes. After enqueuing styles make sure you are calling wp_head() in your header.php file. This function call will auto generate the <link> tags for linking stylesheets for your theme

Link to post
Share on other sites

13 minutes ago, C2dan88 said:

Yes

 

Yes. After enqueuing styles make sure you are calling wp_head() in your header.php file. This function call will auto generate the <link> tags for linking stylesheets for your theme

ok thanks! nothing on the code though I assume it's correct? Also I am a bit new to php do I just write 

wp_head()

to call the function in the header or do I need extra code? 

Link to post
Share on other sites

1 hour ago, C2dan88 said:

Make sure you wrap the function call within php tags. You call the function within the html <head></head> tags in header.php

<?php wp_head(); ?>

 

oh yeah I did wrap it in php tags. Thanks! We'll see if it works now.

 

UPDATE: Well it doesn't. I called the function and same thing no styles,when I view page source I don't see any link tags generated. Is my enqueue code wrong? Also it says undefined function wp_head. 

Link to post
Share on other sites

On 3/5/2022 at 8:49 PM, stefanmz said:

oh yeah I did wrap it in php tags. Thanks! We'll see if it works now.

 

UPDATE: Well it doesn't. I called the function and same thing no styles,when I view page source I don't see any link tags generated. Is my enqueue code wrong? Also it says undefined function wp_head. 

It works I had to use get_template_directory_uri instead of get_template_directory

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×