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

问题描述 投票:0回答:1

我正在尝试在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' );
javascript wordpress enqueue
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(string $ handle,string $ src ='',array $ deps = array(),string | bool | null $ ver = false,bool $ in_footer = false)

如果你的$ handle已经与其他样式或脚本一起存在,那么它将不会被添加到你的主题或插件中,所以要小心这个并添加$ handle的唯一名称

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

参考网站: - qazxsw poi

© www.soinside.com 2019 - 2024. All rights reserved.