My custom stylesheet enqueue function won’t work

I’ve been following a tutorial online thats taught me how to enqueue stylesheets for WordPress with the functions folder instead of the headerusing the following code:

function lucieaverillphotography_scripts() {

wp_enqueue_style( 'lucieaverillphotography_style', get_stylesheet_uri() ); }

Followed by:

Read More
add_action( 'wp_enqueue_scripts', 'lucieaverillphotography_scripts' );

This has worked, but when I tried to enqueue a separate stylesheet for a page template, it won’t work. Here is the code I used, I put it between the two above:

if (is_page_template('page-templates/full-page.php')) {
wp_enqueue_style( 'lucieaverillphotography-full-page' ,
get_template_directory_uri() . '/css/full-page.css');
} 

else { wp_enqueue_style( 'lucieaverillphotography_style', 
get_template_directory_uri() . '/style.css'); }

I have a feeling that it’s something to do with the last part: ‘/style.css’ … but the only way I can get my theme to recognise the new stylesheet is by adding: ‘/css/full-page.css’ in its place and then it uses the new stylesheet for every page rather than the page template.

If I change it by adding the name of the folder that contains style.css – i.e ‘/files/style.css’ , I lose all my css altogether, which is puzzling as I thought this was the most obvious thing to try.

Related posts

1 comment

  1. Try This in functions.php

    function lucieaverillphotography_scripts() {
    
        if (is_page_template('page-templates/full-page.php')) {
            wp_enqueue_style( 'lucieaverillphotography-full-page' , get_template_directory_uri() . '/css/full-page.css');
        }
        else{
            wp_enqueue_style( 'lucieaverillphotography_style', get_stylesheet_uri() );
        }
    
    }
    add_action( 'wp_enqueue_scripts', 'lucieaverillphotography_scripts' );
    

Comments are closed.