繁体   English   中英

我无法在functions.php中添加自定义的CSS和javascript文件

[英]I could not able to add my custom css and javascript files in functions.php

伙计们,我正在尝试在wordpress中添加我的自定义CSS。我已经为每个CSS文件使用了wp_enqueue_style(),但是它不再起作用了。 看看我的functions.php文件。

function theme_add_bootstrap() { 
    wp_enqueue_style( 'style', get_stylesheet_uri() );
    wp_enqueue_style( 'bootstrap-css', get_template_directory_uri() . '/css/bootstrap.min.css' );
    wp_enqueue_style( 'style-css1', get_template_directory_uri() . '/css/mystyle1.css');
    wp_enqueue_style( 'style-css2', get_template_directory_uri() . '/css/mystyle2.css');
    wp_enqueue_style( 'style-css3', get_template_directory_uri() . '/css/nav.css');

    wp_enqueue_style( 'style-css', get_template_directory_uri() . '/style.css');
    wp_enqueue_script( 'bootstrap-js', get_template_directory_uri() . '/js/bootstrap.min.js', array(), '3.0.0', true );
}

add_action( 'wp_enqueue_scripts', 'theme_add_bootstrap' );

如果您没有孩子主题,它确实应该可以工作。

如果您有子主题,则该主题将不起作用,因为get_template_directory_uri()将查找父主题文件夹。

由于只能查找子主题目录文件,因此get_stylesheet_directory_url()仅在其中get_stylesheet_directory_url()

如果您没有子主题,请为add_action()设置优先级

add_action( 'wp_enqueue_scripts', 'theme_add_bootstrap', 10 );

希望这对您有用。

谢谢

暂无
暂无

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

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