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



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

我认为它将添加,但它向您显示CACHE版本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文件(non-Cache)

它已经添加到您的网站上,但是路径是错误的,因此会在控制台上丢弃错误。

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

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

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

如果您的$ hander已经与其他样式或脚本相关,因此不会添加到您的主题或插件中,因此请谨慎,并添加 $ handle的唯一名称

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

倒置网站:-WP Codex WP_enqueue_script

最新更新