Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在wordpress core中加载css和js文件_Php_Wordpress_Bootstrap 4 - Fatal编程技术网

Php 在wordpress core中加载css和js文件

Php 在wordpress core中加载css和js文件,php,wordpress,bootstrap-4,Php,Wordpress,Bootstrap 4,我想在我的WordPress安装中包括引导功能。我知道如何在主题中包含脚本和样式,但这不是我想要的 我查看了WordPress核心文件,并尝试将引导文件添加到script loader.php文件中,但它们不会被加载。有没有办法将这些文件添加到WordPress核心加载的样式和脚本中 例如,我将这一行添加到默认的wordpress样式表/脚本加载程序函数中: $styles->add( 'bootstrap', "/includes/css/bootstrap$suffix.css" );

我想在我的
WordPress安装中包括引导功能
。我知道如何在主题中包含脚本和样式,但这不是我想要的

我查看了WordPress核心文件,并尝试将引导文件添加到
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核心中包含的引导文件有关,我认为他不想使用wordpress函数在主题中加载脚本。我知道如何使用wp_排队函数,我不需要将引导文件嵌入主题中,而是作为依赖项嵌入整个wordpress安装中。