【发布时间】:2017-11-25 06:22:40
【问题描述】:
我已经创建了一个 WordPress 主题的子主题,现在我正在尝试通过修改子主题的 functions.php 将自定义 JavaScript 插入到主页中。但是,我的脚本没有被加载,我不知道为什么。我在 php 代码中插入了 'echo' 语句,看起来像
add_action( 'wp_enque_scripts', 'video_bg', 10);
调用失败
video_bg()
这是我孩子的functions.php:
<?php
add_action( 'after_setup_theme', 'post_theme_setup' );
if ( !function_exists( 'post_theme_setup' )):
function post_theme_setup(){
function video_bg() {
wp_enque_script( 'myVideo', get_stylesheet_directory_uri() . '/JS/filmScript.js', array('jquery'), '1.0.0', false );
echo '<script>console.log("Script added?")</script>';
}
add_action( 'wp_enque_scripts', 'video_bg', 10);
echo '<script>console.log("Loop Entered")</script>';
}
endif;
这是控制台告诉我的:
Loop Entered (index):1
JQMIGRATE: Migrate is installed, version 1.4.1 jquery-migrate.min.js?ver=1.4.1&nocache=1:2
谁能告诉我为什么 video_bg() 永远不会被调用?还是有其他问题?
【问题讨论】:
标签: javascript php wordpress