-2

I'm building my own website within WordPress from scratch. It's not really a new theme, just everything from the beginning, starting with an index file, header, footer, single, comments, functions etc. Utilizing WordPress' features where ever I need them.

I've always been doing good at that, except from when I discovered the Nested comment feature and wanted to tap into that.

But.

I can't get the freaking comment-reply.js to load. Doesn't matter whether I run it in functions or in the header. Even if I just use the raw

wp_enqueue_script( 'comment-reply' )

that should load on each page.

It completely ignores it. If I call the .js file directly by naming the hardcoded url it loads, but this is not the way it's supposed to be coded. It's just a bad work-around.

<?php if ( is_singular() && comments_open() && get_option('thread_comments') ) { ?>
 <script src="<?php bloginfo( 'url' ); ?>/wp-includes/js/comment-reply.js"></script>
<?php } ?>

I've even tried to empty all code out so that the ONLY thing the website does is to load the script but without results. And yes nested comments are activated in settings. I've also tried reinstalling on different domains in case the WP code got screwed.

Any suggestions?

  • Can you clarify if the issue is that the script is not loading (i.e. the script URL is broken/404's), or that it's not running (i.e. throwing an error, check the browser console) – TheDeadMedic Feb 18 '16 at 9:56
  • It's not loading at all. WP completely ignores it. Writing it like this in the header.php works, but that's not how it's intended. <?php if ( is_singular() && comments_open() && get_option('thread_comments') ) { ?> <script src="<?php bloginfo( 'url' ); ?>/wp-includes/js/comment-reply.js"></script> <?php } ?> – Larsps Feb 18 '16 at 10:02
  • Check your conditions. Are the comments open on that page and are your nested comments enabled. If you have disabled any of these the comments won't show up. – denis.stoyanov Feb 18 '16 at 10:06
  • There is no 404. Just ignores the call unless I hardcode the actualy path in an old fashion way. But then that will be broken if WP makes changes to it at a later stage. – Larsps Feb 18 '16 at 10:07
  • Yes, all open and all enabled. And the page also has comments visible. Including nested ones. – Larsps Feb 18 '16 at 10:08
4

Maybe this helps you out?
Please make a backup from functions.php and add following function.

/**
 * Add .js script if "Enable threaded comments" is activated in Admin
 * Codex: {@link https://developer.wordpress.org/reference/functions/wp_enqueue_script/}
 */
function wpse218049_enqueue_comments_reply() {

    if( is_singular() && comments_open() && ( get_option( 'thread_comments' ) == 1) ) {
        // Load comment-reply.js (into footer)
        wp_enqueue_script( 'comment-reply', '/wp-includes/js/comment-reply.min.js', array(), false, true );
    }
}
add_action(  'wp_enqueue_scripts', 'wpse218049_enqueue_comments_reply' );

Note: see codex on how to enqueue

| improve this answer | |
  • No sorry, that's what is not working for me. The wp_enqueue_script( 'comment-reply' ); is completely being ignored by WP. But I've done it the manual way and that works out just fine. I was just wondering if anyone knew why it is like that. – Larsps Feb 19 '16 at 10:42
  • @Larsps, I would check the issue with the twentysixteen theme and all plugins disabled. Imho is the 'works out just fine' already pointing you on possible new issues into the future. As already mentioned by yourself, you have no clue what the cause is which makes Wordpress behaving like it does right now for you, so stable warranties are already gone I would say. But you are right, as long it seems to work for you be happy :) (updated the plugin though, for others it probably will work like a charm) – Charles Feb 19 '16 at 11:40
  • I've checked already with standard themes and there it loads just fine. So when my own theme is completely stripped for everything, there much be something that trickers/enables comment-reply that I currently don't have. I don't know whether I'll ever figure it out since I seem to be the only person on the Internet that has this problem (I've done my research). But my bad work around is working just fine for now lowhangingfruits.com/work/… – Larsps Feb 19 '16 at 16:17
0

I had this problem too. I found out that the comment-reply.js is loaded at the bottom of the page, so you won't find it in your header. Make sure you have wp_footer() inside your footer.php.

| improve this answer | |

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.