我正在开发一个主题并试图让 wp_enqueue_script 工作。奇怪的是,什么也没有出现。它什么都不做。这是我的设置:
在 functions.php 我有:
function named_scripts() {
global $named_options;
if( is_admin() ) return;
wp_deregister_script( 'jquery' );
wp_register_script( 'screen', tz_JS . '/screen.js', array( 'jquery' ) );
wp_enqueue_script( 'screen' );
wp_enqueue_script( 'bootstrap', tz_JS . '/bootstrap/bootstrap.js', array( 'jquery' ) );
wp_register_style( 'custom-style', get_template_directory_uri() . '/css/custom-style.css', array(), '20120208', 'all' );
wp_enqueue_style( 'custom-style' );
}
add_action( 'init', 'named_scripts' );
在 header.php 中调用
named_scripts();
在 HTML 中,什么也没有显示。
最佳答案
在删除默认的 wordpress jquery 之后,您应该已经注册了您的 jquery 文件。我使用这段代码..希望它有帮助..
function load_external_jQuery() { // load external file
wp_deregister_script( 'jquery' ); // deregisters the default WordPress jQuery
wp_register_script('jquery', ("http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"), false);
wp_enqueue_script('jquery');
wp_register_script('blur', get_template_directory_uri() . '/_/js/blur.js', array('jquery') );
wp_enqueue_script('blur');
}
add_action('wp_enqueue_scripts', 'load_external_jQuery');
关于javascript - WordPress wp_enqueue_script 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14606823/