[英]Wordpress - wp_enqueue_script / wp_enqueue_style doesn't work
[英]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(字符串$ handle,字符串$ src ='',數組$ deps = array(),字符串| bool | null $ ver = false,bool $ in_footer = false)
如果您的$ handle已經與其他樣式或腳本一起存在,因此不會將其添加到您的主題或插件中,請對此謹慎,並添加$ handle的唯一名稱
注意:-添加$ handle的唯一名稱或在$ handle的名稱之前添加自己的前綴,例如custom_jquery,這是我們的自定義jquery $ handle名稱
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.