wp_list_comments reply-link抛出Uncaught TypeError

问题描述 投票:0回答:1

使用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控制台会抛出错误:

我希望textarea会在点击回复按钮后显示在当前评论下。

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)

现在出乎意料的行为。我正在使用Plugin 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扩展导致上述错误的情况。但遗憾的是,给定的解决方案(禁用和/或从扩展程序注销)并没有成功。

javascript php wordpress
1个回答
0
投票

解决方案(至少对我而言)是添加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(); ?>

© www.soinside.com 2019 - 2024. All rights reserved.