排队样式和脚本 WordPress 不起作用

enqueue style and script WordPress doesn't work

我正在尝试在 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' );

我认为它会被添加,但它会向您显示缓存版本 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( string $handle, string $src = '', array $deps = array(), string|bool|null $ver = false, bool $in_footer =假)

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

Note :- Add Unique name of $handle or add your own prefix before name of $handle like custom_jquery this is our custom jquery $handle name

参考站点:- WP Codex wp_enqueue_script