简体   繁体   English

我的自定义样式表入队功能不起作用

[英]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: 我一直在关注在线教程,该教程教我如何使用functions文件夹(而不是标题)使用以下代码将Wordpress的样式表入队:

function lucieaverillphotography_scripts() {

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

Followed by: 其次是:

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. 我感觉这与最后一部分有关:'/style.css'...但是,要让我的主题能够识别新样式表的唯一方法是添加:'/css/full-page.css ”,然后为每个页面而不是页面模板使用新的样式表。

If I change it by adding the name of the folder that contains style.css - ie '/files/style.css' , I lose all my css altogether, which is puzzling as I thought this was the most obvious thing to try. 如果我通过添加包含style.css的文件夹的名称来更改它-即'/files/style.css',那么我将完全失去所有的CSS,这令人困惑,因为我认为这是最显而易见的尝试。

Try This in functions.php 在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' );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM