admin管理员组文章数量:1333398
I want to enqueue my plugin for certain pages. I've tried several things but nothing worked so far:
add_action( 'init', 'my_enqueue' );
function my_enqueue() {
global $post;
if( $post->ID == 380 || is_home() || is_front_page() || is_single(380) || is_page(380)) {
wp_enqueue_script( 'lister_js', plugins_url( '/js/lister.js', __FILE__ ), array('jquery'), filemtime( '/js/lister.js', __FILE__ ));
wp_localize_script( 'lister_js', 'my_ajax_object', array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) );
}
}
The post id is 380 according to the db. I even checked the url and it is ".../wp-admin/post.php?post=380&action=edit". So I'm pretty sure the id is correct.
I want to enqueue my plugin for certain pages. I've tried several things but nothing worked so far:
add_action( 'init', 'my_enqueue' );
function my_enqueue() {
global $post;
if( $post->ID == 380 || is_home() || is_front_page() || is_single(380) || is_page(380)) {
wp_enqueue_script( 'lister_js', plugins_url( '/js/lister.js', __FILE__ ), array('jquery'), filemtime( '/js/lister.js', __FILE__ ));
wp_localize_script( 'lister_js', 'my_ajax_object', array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) );
}
}
The post id is 380 according to the db. I even checked the url and it is ".../wp-admin/post.php?post=380&action=edit". So I'm pretty sure the id is correct.
Share Improve this question asked Jun 20, 2020 at 12:18 KitiaraKitiara 1114 bronze badges1 Answer
Reset to default 0It started to work once i change
add_action( 'init', 'my_enqueue' );
to
add_action( 'wp_enqueue_scripts', 'my_enqueue' );
本文标签: Enqueue plugin for specific pages
版权声明:本文标题:Enqueue plugin for specific pages 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742331678a2454818.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论