我已经成功地在WordPress中加载js文件很多次了,这让我很难过。这是我目前为我的孩子主题设置但没有成功(奇怪的是googlemaps.js正在正确加载):
function theme_js() {
wp_enqueue_script( 'theme_js', get_stylesheet_directory_uri() .
'/js/googlemaps.js', array( 'jquery' ), '1.0', true );
wp_enqueue_script( 'theme_js', get_stylesheet_directory_uri() .
'/js/toggler.js', array( 'jquery' ), '1.0', true );
}
add_action('wp_enqueue_scripts', 'theme_js');
我尝试将数组替换为NULL(' jquery')位无效。我在这里不知所措。有很多Stack Overflow问题解决了这个问题,但我见过的大多数都有明显的错别字或其他问题,我已经检查了四倍。 (我已经包含了儿童主题文件结构的屏幕截图,仅供参考) screenshot of file structure within child theme
答案 0 :(得分:0)
这正是问题所在。它应该绝对不是'theme_js'它应该是该特定脚本的名称,它曾经改为'toggler'
wp_enqueue_script( 'toggler', get_template_directory_uri() .
'/js/toggler.js', array( 'jquery' ), '1.0', true );