0

我正在尝试在 WordPress 中将 javascript 和 css 排入队列。我已经编写了以下代码,但它不起作用,并且没有样式或 css 被添加到我的主题中。

function add_theme_scripts() {

  wp_enqueue_style( 'cssdatepicker', get_template_directory_uri() . '/css/persian-datepicker.css', array(), '1.1', 'all');

  wp_enqueue_script( 'jsdate', get_template_directory_uri() . '/js/persian-date.js', array ( 'jquery' ), '1.1', true);
   wp_enqueue_script( 'jsdatepicker', get_template_directory_uri() . '/js/persian-datepicker.js', array ( 'jquery' ), '1.1', true);

}
add_action( 'wp_enqueue_scripts', 'add_theme_scripts' );
4

1 回答 1

1

我认为它会被添加,但它显示缓存版本 CSS 和 js 可能是空白的

function add_theme_scripts() {

  wp_enqueue_style( 'cssdatepicker', get_template_directory_uri(). '/css/persian-datepicker.css', array(), null, 'all');

  wp_enqueue_script( 'jsdate', get_template_directory_uri() . '/js/persian-date.js', array ( 'jquery' ), null, true);
   wp_enqueue_script( 'jsdatepicker', get_template_directory_uri() . '/js/persian-datepicker.js', array ( 'jquery' ), null, true);

}
add_action( 'wp_enqueue_scripts', 'add_theme_scripts' );

使用此代码运行更新的 js 和 CSS 文件(非缓存)

  • 或者

它已经添加到您的站点,但路径错误,因此它会在控制台中引发错误。

您可以使用 F12 键在控制台中看到

请检查并让我知道您的状态。

  • 或者

wp_enqueue_script(字符串 $handle,字符串 $src = '',数组 $deps = array(),字符串|bool|null $ver = false,bool $in_footer = false)

如果您的 $handle 已经存在于其他样式或脚本中,因此它不会添加到您的主题或插件中,因此请注意这一点并添加$handle的唯一名称

注意:- 添加唯一的 $handle 名称或在 $handle 名称之前添加您自己的前缀,如custom_jquery这是我们自定义的jquery $handle 名称

参考网站:- WP Codex wp_enqueue_script

于 2019-03-11T07:29:06.420 回答