Wordpress wp_enqueue_script不工作

Wil*_*m H 5 javascript wordpress

我正在开发一个主题并尝试让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' );
Run Code Online (Sandbox Code Playgroud)

在header.php我打电话

named_scripts();
Run Code Online (Sandbox Code Playgroud)

而在HTML中,根本没有任何显示.

小智 8

删除默认的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');
Run Code Online (Sandbox Code Playgroud)