php加载css文件,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 );

第二个是添加JS

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

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

最终你会有这样的事情:

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' );

祝好运!

标签:wordpress,php,bootstrap-4

来源: https://codeday.me/bug/20190701/1346051.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值