WordPress将脚本和样式排入队列

我使用开源WordPress主题,并希望从header.php文件中删除样式和脚本并正确编写它们。 我已经将以下代码添加到我的functions.php文件中,没有任何反应。

function smarter_scripts() { wp_enqueue_style( 'smarter-bootstrap', '//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css' ); wp_enqueue_style( 'smarter-font-awesome', '//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.4.0/css/font-awesome.min.css' ); wp_enqueue_style( 'smarter-google-fonts-open-sans', '//fonts.googleapis.com/css?family=Open+Sans:600,400,300,700' ); wp_enqueue_style( 'smarter-google-fonts-josefin', '//fonts.googleapis.com/css?family=Josefin+Sans:400,600' ); wp_enqueue_style( 'smarter-style', get_template_directory_uri(). '/style.css' ); if (!is_admin()) { // comment out the next two lines to load the local copy of jQuery //wp_deregister_script('jquery'); //wp_register_script('jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js', false, '1.11.2'); wp_enqueue_script('jquery'); } // load a JS file from my theme: js/theme.js wp_enqueue_script('smarter_script', get_template_directory_uri() . '/js/script.js', array('jquery'), '1.0', true); wp_enqueue_script( 'smarter-bootstrap','//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js', array( 'jquery' ), true ); } add_action( 'wp_enqueue_scripts', 'smarter_scripts' ); 

另外,我无法弄清楚为什么当我添加插件时,CSS和JS文件不会自动加载主题。 我必须手动将文件添加到header.php或footer.php文件中才能使插件正常工作。 有谁知道为什么会这样? (我不是主题开发人员,但我正在尝试修复我公司正在使用的主题。)

参考:

WordPress:使用enqueue加载多个脚本

在函数中使用此code.before函数

  if ( ! function_exists( 'smarter_scripts' ) ) { 

然后在关闭此if条件之前放置此代码。

 add_action( 'wp_enqueue_scripts', 'smarter_scripts', 99); 

在header.php文件中,在代码之前放置代码