WordPress 插件开发wp_enqueue_script()引入jQuery无效

2020/10/04 11:41

我试了很多次,Wordpress里用wp_enqueue_script()引入jquery都是无效的,也就是用Wordpress内置的jquery,这样就不用二次加载浪费资源。

后来发现使用wp_enqueue_script()引入jquery需要将jquery语法改成如,也就是将“$”改为“jQuery”。

//enqueue css and js in admin panel
function admin_add_bld_pay_scripts() {
    wp_enqueue_style('bld-pay-style', plugin_dir_url( __FILE__ ). 'assets/css/bld-pay-style.css');
    wp_enqueue_script( 'insert_short_code', plugin_dir_url( __FILE__ ).'assets/js/insert_short_code.js',
array('jquery'),null,true);
}
add_action('admin_enqueue_scripts', 'admin_add_bld_pay_scripts');
jQuery(document).ready(function(){
    jQuery('#insert_pp_code').click(function(){
    alert('xxx');
    });
});

发表回复

Back to top