繁体   English   中英

wp_list_comments回复链接引发未捕获的TypeError

[英]wp_list_comments reply-link throws Uncaught TypeError

使用wp_list_comments时遇到一些意外行为。

生成的链接:

<a rel="nofollow" class="comment-reply-link" href="http://localhost/mypost/?replytocom=2#respond" onclick="return addComment.moveForm( &quot;div-comment-2&quot;, &quot;2&quot;, &quot;respond&quot;, &quot;9&quot; )" aria-label="reply to NAME">Reply</a>

当我单击回复链接时,JavaScript控制台抛出错误:

希望单击“回复”按钮时,文本区域将显示在当前注释下。

Uncaught TypeError: Cannot read property 'getElementsByTagName' of null
    at Object.moveForm (comment-reply.min.js?ver=4.9.4:1)
    at HTMLAnchorElement.onclick (VM18269:489)

现在到意外的行为。 我正在使用插件AdvancedCustomFields。 当我禁用插件时,将引发以下错误:

Uncaught ReferenceError: addComment is not defined
    at HTMLAnchorElement.onclick (VM18404:489)

为了解决此特定问题,我尝试手动添加comment-reply.js

functions.php

// enable reply to comments 
function theme_queue_js(){
if ( (!is_admin()) && is_singular() && comments_open() && get_option('thread_comments') )
  wp_enqueue_script( 'comment-reply' );
}
add_action('wp_enqueue_scripts', 'theme_queue_js');

但是,这并没有使脚本入队。 仍然抛出Uncaught ReferenceError (请注意,仍然禁用了ACF插件)。

comments.php

    <ul id="comments">
    <?php wp_list_comments(array(
        'walker'            => null,
        'max_depth'         => '',
        'style'             => 'ul',
        'callback'          => null,
        'end-callback'      => null,
        'type'              => 'comment',
        'reply_text'        => 'Reply',
        'page'              => '',
        'per_page'          => '',
        'avatar_size'       => 32,
        'reverse_top_level' => null,
        'reverse_children'  => '',
        'format'            => 'html5', // or 'xhtml' if no 'HTML5' theme support
        'short_ping'        => false,   // @since 3.6
        'echo'              => true     // boolean, default is true
    )); ?>
    </ul>

一些或多或少有用的信息:

  • 我正在使用comment-list主题支持
  • 我已经清除了缓存
  • 我使用了其他多个浏览器(已登录和已注销)
  • 没有引发其他JavaScript错误

我已经做了很多研究。 我还偶然发现LastPass Extension导致上述错误的情况。 但是不幸的是,给定的解决方案(禁用扩展名和/或从扩展名注销)对我没有帮助。

解决方案(至少对我而言)是添加comment_form()

我设法监督了几个小时的简单功能。

<div id="comments">
<ul>
    <?php wp_list_comments(array(
        'walker'            => null,
        'max_depth'         => '',
        'style'             => 'ul',
        'callback'          => null,
        'end-callback'      => null,
        'type'              => 'comment',
        'reply_text'        => 'Reply',
        'page'              => '',
        'per_page'          => '',
        'avatar_size'       => 32,
        'reverse_top_level' => null,
        'reverse_children'  => '',
        'format'            => 'html5', // or 'xhtml' if no 'HTML5' theme support
        'short_ping'        => false,   // @since 3.6
        'echo'              => true     // boolean, default is true
    )); ?>
</ul>

<?php comment_form(); ?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM