Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php wordpress wp_enque_脚本不工作_Php_Wordpress - Fatal编程技术网

Php wordpress wp_enque_脚本不工作

Php wordpress wp_enque_脚本不工作,php,wordpress,Php,Wordpress,试图安全地注册和enque一些脚本,但它不起作用。当我查看页面源代码时,我可以看到脚本正在加载,但它们不工作。如果我在页眉或页脚中包含脚本(错误的方式),它们就可以正常工作。下面是我在主题的functions.php文件中的代码。有什么想法吗 if (function_exists('register_my_js')) { function register_my_js() { if ( !is_admin() ) { wp_register_script( 'isotop

试图安全地注册和enque一些脚本,但它不起作用。当我查看页面源代码时,我可以看到脚本正在加载,但它们不工作。如果我在页眉或页脚中包含脚本(错误的方式),它们就可以正常工作。下面是我在主题的functions.php文件中的代码。有什么想法吗

if (function_exists('register_my_js')) {
function register_my_js()
{
    if ( !is_admin() )
  {

    wp_register_script( 'isotope', get_template_directory_uri() . '/js/isotope.min.js', array( 'jquery' ),'', true );

    wp_register_script( 'isotope-custom', get_template_directory_uri() . '/js/isotope-custom.js', array( 'jquery' ),'', true );

    wp_register_script( 'bootstrap', get_template_directory_uri() . '/js/bootstrap.js', array( 'jquery' ),'', true );

    wp_register_script( 'plugins', get_template_directory_uri() . '/js/plugins.js', array( 'jquery' ),'', true );

    wp_register_script( 'common', get_template_directory_uri() . '/js/common.js', array( 'jquery' ),'', true );

    wp_enqueue_script( 'jquery' );
    wp_enqueue_script( 'isotope' );
    wp_enqueue_script( 'isotope-custom' );
    wp_enqueue_script( 'bootstrap' );
    wp_enqueue_script( 'plugins' );
    wp_enqueue_script( 'common' );

       }

    }
}

add_action('init', 'register_my_js');

你用错钩子了。所有样式表和jquery脚本都应该连接到
wp\u enqueue\u脚本

所以改变

add_action('init', 'register_my_js');


您还需要将第一行从函数_exists更改为!函数_存在。这样,该函数将实际工作。我建议你加上

add_action('wp_enqueue_scripts', 'register_my_js');
在最后一次争吵之前

add_action('wp_enqueue_scripts', 'register_my_js');