0

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.

1 Answer 1

0

It started to work once i change

add_action( 'init', 'my_enqueue' );

to

add_action( 'wp_enqueue_scripts', 'my_enqueue' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.