php – 在wordpress核心中加载css和js文件

我想在我的wordpress安装中包含bootstrap.我知道如何在主题中包含脚本和样式,但这不是我想要的.

我查看了wordpress核心文件,并尝试将bootstrap文件添加到script-loader.PHP文件中,但不会加载它们.有没有办法将这些文件添加wordpress核心加载的样式和脚本?

例如,我已将此行添加认的wordpress样式表/脚本加载器函数中:

$styles->add( 'bootstrap', "/includes/css/bootstrap$suffix.css" );
$scripts->add( 'bootstrap', "/includes/js/bootstrap$suffix.js", array( 'jquery' ) );

但这不行.

解决方法:

我会通过改变你当前主题中的functions.PHP来做到这一点.
您应该了解两个功能.第一个添加CSS.

wp_enqueue_style( $handle, $src, $deps, $ver, $media );

Documentation

第二个是添加JS

wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer);

Documentation

wordpress一个关于如何做到这两点的基本文档:

Documentation

最终你会有这样的事情:

function add_theme_scripts() {
  wp_enqueue_style( 'style', get_stylesheet_uri() );

  wp_enqueue_style( 'slider', get_template_directory_uri() . '/css/slider.css', array(), '1.1', 'all');

  wp_enqueue_script( 'script', get_template_directory_uri() . '/js/script.js', array ( 'jquery' ), 1.1, true);

    if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
      wp_enqueue_script( 'comment-reply' );
    }
}
add_action( 'wp_enqueue_scripts', 'add_theme_scripts' );

祝好运!

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...