繁体   English   中英

重新定位Wordpress评论回复表单的“取消回复”链接

[英]Relocate the 'cancel reply' link of the Wordpress comment reply form

我已经将Wordpress的“回复”表单设置为与主要的“评论”表单不同的样式。

我想从“回复”表单中删除“评论回复标题”(“留下回复”)。 我已经通过display: none成功完成了此操作display: none 不幸的是,“取消回复”链接与“ comment-reply-title”位于同一div中,因此该链接也被删除。

我已经在互联网上搜索了将“取消回复”链接移至该div以外的位置的解决方案; 就我而言,我想将其放在默认的“答复”链接旁边; 或者,如果无法实现,请点击“提交”按钮旁边。

有人可以帮我吗?

您可以使用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: ' \00B7\0020';
}

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

我找到了一种使用挂钩而不是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);

暂无
暂无

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

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