2016-03-08 22 views
0

怎麼有選擇在WP中獲取兒童主題的js文件?如何獲取兒童主題的js文件?

我只能得到孩子主題的css文件像這樣,

wp_enqueue_script('custom', get_bloginfo('stylesheet_url') . '/js/custom.js', array()); 

但我想在我的孩子主題的JS文件夾中的js文件。

可能嗎?

編輯:

有了這個,

$jsPath = get_stylesheet_directory() . '/js/yourScript.js'; 
wp_enqueue_script('child-js', $jsPath, array(), '1.0', true) 

我會得到:

http://{127.0.0.1}/projects/mysite/var/www/projects/mysite/wp-content/themes/vantage-child/js/custom.js?ver=1.0' 

哪項是錯誤的,即使它獲得的子主題文件夾正確的 - 但增加了額外的路徑我不需要var/www/projects/mysite/

回答

1

您可以使用get_stylesheet_directory_uri()獲取主題文件夾路徑URI - 請參閱:https://codex.wordpress.org/Function_Reference/get_stylesheet_directory_uri。然後使用類似的方式引用你的JS文件。

$jsPath = get_stylesheet_directory_uri().'/js'; 
wp_enqueue_script('js-file', $jsPath.'/script.js', array(), '1.0', true); 
+0

完美!非常感謝:D – laukok

+1

沒問題 - 樂意幫忙! –