0

I'm trying to enqueue comment-reply.js script only on a certain page but something is wrong with my code. Can someone hint things here?

<?php if ( is_singular('1740') && (!is_home() || !is_front_page() || !is_single()) && comments_open() && get_option('thread_comments') ) wp_enqueue_script( 'comment-reply' ); ?>
2
  • 2
    I think is_singular() accepts only str|array of post type name, not a post ID. You could use is_single or is_page. Unless 1740 is a valid CPT :D – Ismail Jan 29 '17 at 15:30
  • @SamuelElh I think that the problem was is_singular('1740'). I ended up using this and it worked: <?php if ( is_page('1740')) {wp_enqueue_script( 'comment-reply' );} ?> – bpy Jan 29 '17 at 19:12
0

I think the conditional tag which is comments_open() is not required. That checks if the comments are allowed for that specific page or not.

Try using the following code

<?php
if ( is_single('1740') ||
( !is_home() || !is_front_page() || !is_single() ) ) {
    wp_enqueue_script( 'comment-reply' );
} ?>

comments_open() requires the post ID for the specific posts to check whether the comments are allowed or not. So avoid using the condition for that.

Don't use is_singular() with ID as it checks if a singular post is being displayed using the post type name as a parameter. Instead use is_single() with using the post ID for which you wish to display.

In your above code, the flower bracket was missing too for the if condition.

Hope that helps the question you have asked.

1
  • not working... Even with your code I get comment-reply on home/front_page and single posts... What I'm I missing? – bpy Jan 29 '17 at 15:39
0

Try adding the following code and let me know

if ( is_singular('1740') && comments_open() && get_option( 'thread_comments' ) ) {
    wp_enqueue_script( 'comment-reply' );
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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