简体   繁体   English

排队样式和脚本WordPress无法正常工作

[英]enqueue style and script WordPress doesn't work

I'm trying to enqueue javascript and css in WordPress. 我正在尝试在WordPress中加入javascript和CSS。 I have written the following code but it is not working and no style or css is being added to my theme. 我已经编写了以下代码,但无法正常工作,并且没有在我的主题中添加任何样式或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' );

I think it will be added but it showing you cache version CSS and js which is blank maybe 我认为它将被添加,但是它向您显示缓存版本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' );

use this code to run updated js and CSS file ( non-cache ) 使用此代码运行更新的js和CSS文件(非缓存)

  • OR 要么

it is already added to your site but the path is wrong so it will throw an error in console. 它已经添加到您的网站,但是路径错误,因此它将在控制台中引发错误。

you can see in the console using the F12 key 您可以使用F12键在控制台中看到

please check and let me know what is your status. 请检查,让我知道您的身份。

  • OR 要么

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

if your $handle has already existed with other style or script so it will not be added to your theme or plugin so be careful about this and add the unique name of $handle 如果您的$ handle已经与其他样式或脚本一起存在,因此不会将其添加到您的主题或插件中,请对此谨慎,并添加$ handle的唯一名称

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 注意:-添加$ handle的唯一名称或在$ handle的名称之前添加自己的前缀,例如custom_jquery,这是我们的自定义jquery $ handle名称

Refrence site :- WP Codex wp_enqueue_script Refreence网站: -WP Codex wp_enqueue_script

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM