WordPress-在index.php上加载自定义CSS [英] Wordpress - loading custom css on index.php

查看:61
本文介绍了WordPress-在index.php上加载自定义CSS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为index.php加载自定义布局样式.我的主题叫做kendo,我正在尝试在functions.php中提取一些自定义样式表

i am trying to load custom layout style for index.php. My theme is called kendo and i am trying to pull some custom stylesheets in functions.php

样式表是分开工作的(例如,如果我删除一行),但它们会相互覆盖.我的代码有问题吗?

Stylesheets work separately (if i delete one line for example), but they keep overriding each other. Is something wrong with my code?

function kendo_scripts() {
    wp_enqueue_style( 'kendo-style', get_stylesheet_uri() );

    if (is_page_template('index'))  {
        wp_enqueue_style( 'kendo-layout-style1', get_template_directory_uri() . '/layouts/no-sidebar.css' );
    }
    if (!is_page_template('index')) {
        wp_enqueue_style( 'kendo-layout-style2', get_template_directory_uri() . '/layouts/content-sidebar.css' );
    }

推荐答案

将其添加到header.php会更容易...

Wouldn't adding this to header.php be easier...

<?php if (is_front_page()) { ?>
<link rel="stylesheet" type="text/css" href="<?php bloginfo('stylesheet_directory'); ?>/css/stylesheet1.css"/>
<?php } else { ?>
<link rel="stylesheet" type="text/css" href="<?php bloginfo('stylesheet_directory'); ?>/css/stylesheet2.css"/>
<?php } ?>

这篇关于WordPress-在index.php上加载自定义CSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆