【问题标题】:How to load Bootstrap on wordpress home page **only**如何在 wordpress 主页上加载 Bootstrap **仅限**
【发布时间】:2021-03-14 23:07:50
【问题描述】:

我有一个 wordpress 网站并添加了引导程序。现在引导程序正在与另一个页面上的一些设计混淆,而我唯一需要引导程序的是主页上的一些卡片。请问有没有办法让引导程序只在主页上工作?

这是我在下面的functions.php中添加的代码:

function bootstrap_script() {
    wp_register_style('bootstrap', get_template_directory_uri().'/styles/bootstrap.min.css');
    wp_enqueue_style('bootstrap');
}
add_action( 'wp_enqueue_scripts', 'bootstrap_script');

【问题讨论】:

    标签: php wordpress twitter-bootstrap bootstrap-4


    【解决方案1】:

    难以置信,但如果您指的是博客页面,您可以使用函数is_home()

    function bootstrap_script() {
    
        if ( is_home() ) {
            wp_enqueue_style('bootstrap', get_template_directory_uri().'/styles/bootstrap.min.css');
        }
    }
    add_action( 'wp_enqueue_scripts', 'bootstrap_script');
    

    【讨论】:

    • 这不是博客页面。这是一个静态主页
    • 你可以用is_front_page()代替is_home()
    • @pj-c0d3r 您可以将此答案标记为已接受,只需单击投票按钮下方的复选标记
    猜你喜欢
    • 2021-03-15
    • 2015-02-04
    • 1970-01-01
    • 1970-01-01
    • 2021-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-08
    相关资源
    最近更新 更多