wp enqueue script - comment-reply.js is not loading

I'm building my own website within WordPress from scratch. It's not really a new theme, just everything from t

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?

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?

Share Improve this question edited Feb 18, 2016 at 10:09 Larsps asked Feb 18, 2016 at 9:32 LarspsLarsps 111 silver badge3 bronze badges 7
  • 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 Commented Feb 18, 2016 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 Commented Feb 18, 2016 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 Commented Feb 18, 2016 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 Commented Feb 18, 2016 at 10:07
  • Yes, all open and all enabled. And the page also has comments visible. Including nested ones. – Larsps Commented Feb 18, 2016 at 10:08
 |  Show 2 more comments

2 Answers 2

Reset to default 5

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/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

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745496472a4630211.html

相关推荐

  • wp enqueue script - comment-reply.js is not loading

    I'm building my own website within WordPress from scratch. It's not really a new theme, just everything from t

    5小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信