重新定位 Wordpress 评论回复表单的'cancel reply'链接



我对WordPress"回复"表格进行了设计,而不是主"注释"表单。

我想从"回复"表格中删除"评论 - reply-title"("丢失回复"(。我已经成功地使用了display: none。不幸的是,"取消回复"链接位于'评论 - reply-title'的同一 div中,因此也正在删除链接。

我已经搜索了Internet的解决方案,以将此DIV之外的"取消回复"链接移至另一个位置;就我而言,我想将其放在默认"回复"链接旁边;或者如果不可能,则在提交按钮旁边。

有人可以帮我吗?

我找到了一种使用钩子而不是jQuery进行此操作的方法。以下将添加取消按钮到表格的末尾。

// Remove the comment reply button from it's default location
function my_remove_comment_reply_link($link) {
    return '';
}
add_filter('cancel_comment_reply_link', 'ndic_remove_comment_reply_link', 10);
// Add the comment reply button to the end of the comment form.
// Remove the my_remove_comment_reply_link filter first so that it will actually output something.
function my_after_comment_form($post_id) {
    remove_filter('cancel_comment_reply_link', 'ndic_remove_comment_reply_link', 10);
    cancel_comment_reply_link('Cancel reply');
}
add_action('comment_form', 'my_after_comment_form', 99);

您可以使用jQuery进行。

footer.php 模板中的关闭</body>标签之前添加此内容:

<script>
jQuery( function( $ ){
    $( '.comment-reply-link', '.comment-body' ).on( 'click', function(){
        $( '#cancel-comment-reply-link' ).insertAfter( this ).show();
    } );
    $( '#cancel-comment-reply-link' ).on( 'click', function(){
        $( this ).hide();
    } );
} );
</script>

然后使用自定义器添加此自定义CSS :(如果需要帮助,请单击此处(

(
.reply #cancel-comment-reply-link:before {
    /* This will print a middle-dot character with leading spaces. */
    content: ' 0B7020';
}

(您还可以将代码直接添加到主题的 style.css 文件中。(

最新更新