Javascript 在Wordpress插件中包含jQuery
我在Wordpress插件中使用jQuery/ajax。当我以这种方式链接jQuery时,它甚至可以工作Javascript 在Wordpress插件中包含jQuery,javascript,php,jquery,wordpress,Javascript,Php,Jquery,Wordpress,我在Wordpress插件中使用jQuery/ajax。当我以这种方式链接jQuery时,它甚至可以工作 add_action('wp_head', 'hook_files'); function hook_files() { $output = " <script src='https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js'></script> <script s
add_action('wp_head', 'hook_files');
function hook_files()
{
$output = "
<script src='https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js'></script>
<script src='//code.jquery.com/ui/1.11.2/jquery-ui.js'></script>
<link rel='stylesheet' href='//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css'> ";
echo $output;
}
但是它不再起作用了。。。有什么不对劲吗
谢谢 我建议使用队列加载脚本,特别是jquery,这样您就可以像这样启动它:[推荐的解决方案]
wp_enqueue_script('jquery');
或者是一种更为高谈阔论的方法:
function my_scripts() {
wp_enqueue_script( 'jquery' );
wp_register_style( 'prefix-style', plugins_url('mystyle.css', __FILE__) );
wp_enqueue_style( 'prefix-style' );
}
add_action('wp_enqueue_scripts','my_scripts');
除非您想对jquery使用cdn或google回购,否则我建议您执行以下操作:
wp_enqueue_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js', array('jquery'));
wp_enqueue_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js', array('jquery'));