【问题标题】:My custom stylesheet enqueue function won't work我的自定义样式表入队功能不起作用
【发布时间】:2016-04-06 18:36:42
【问题描述】:

我一直在关注一个在线教程,该教程教我如何使用以下代码将 Wordpress 的样式表与函数文件夹而不是标题一起排入队列:

function lucieaverillphotography_scripts() {

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

接着是:

add_action( 'wp_enqueue_scripts', '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_template_directory_uri() . '/style.css'); }

我觉得这与最后一部分有关:'/style.css' ...但我可以让我的主题识别新样式表的唯一方法是添加:'/css/full- page.css' 代替它,然后它为每个页面使用新样式表,而不是页面模板。

如果我通过添加包含 style.css 的文件夹的名称来更改它 - 即 '/files/style.css' ,我会完全丢失我所有的 css,这令人费解,因为我认为这是最明显的事情试试看。

【问题讨论】:

    标签: php html css wordpress


    【解决方案1】:

    在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' );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-04
      • 2014-10-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多