【问题标题】:Wordpress remove comment_form( 'cancel_reply_link' )?Wordpress 删除 comment_form('cancel_reply_link')?
【发布时间】:2015-04-23 09:03:41
【问题描述】:

自定义我的评论模板,我正在使用comment_form 函数。

http://codex.wordpress.org/Function_Reference/comment_form

通过用空白值覆盖默认值来删除某些内容似乎很容易,例如表单下方的“您可以使用这些标签和属性”的文本和其他内容。但是,它不允许您从模板中删除 `cancel_reply_link',因为从数组中删除它的值仍然会使其显示为默认值。

<?php
    comment_form(
        array(
            'comment_notes_after'   => '',
            'title_reply'           => '',
            'comment_field'         => '<textarea id="comment" name="comment" aria-required="true" placeholder="Leave a comment..."></textarea>',
            'logged_in_as'          => '',
            'cancel_reply_link'     => ''
        )
    );
?>

如您所见,cancel_reply_link 为空,但它仍会在我的评论 textarea 之前输出以下 HTML。

<h3 id="reply-title" class="comment-reply-title">
    <small>
        <a rel="nofollow" id="cancel-comment-reply-link" href="/websites/wordpress/post-6/comment-page-1/#respond">Click here to cancel reply.</a>
    </small>
</h3>

如何删除此h3 及其内容?

我想要删除它的原因是,当人们回复其他 cmets 时,我可以简单地在 textarea 下方的“提交”按钮旁边添加一个“取消”按钮。

谢谢。

http://i.stack.imgur.com/Gsjdi.png

【问题讨论】:

    标签: wordpress wordpress-theming


    【解决方案1】:

    您在这里有几个选择。一种是使用 css 向用户隐藏该元素。

    h3.comment-reply-title { display: none) 
    

    另一种选择可能是使用'cancel_comment_reply_link' 过滤器来编辑html。

    https://core.trac.wordpress.org/browser/tags/4.1.1/src/wp-includes/comment-template.php#L1549

    【讨论】:

    • 宁愿删除它也不愿隐藏它。我会看看那个文件,看看我能想出什么。谢谢老兄。
    【解决方案2】:

    如果你想删除取消链接,你需要使用 wordpress 内置的 __return_false 函数来为过滤器返回 false 值,如下所示:

    add_filter( 'cancel_comment_reply_link', '__return_false' );
    

    这已经回答here

    上述函数驻留在wp-includes/functions.php中:

    function __return_false() {
        return false;
    }
    

    在 wp-includes/functions.php 中有更多类似的函数返回过滤器的常用值,例如:__return_true__return_empty_string

    【讨论】:

    • 欢迎提供解决方案链接,但请确保您的答案在没有它的情况下有用:add context around the link 这样您的其他用户就会知道它是什么以及为什么会出现,然后引用最相关的您链接到的页面的一部分,以防目标页面不可用。 Answers that are little more than a link may be deleted.
    • 谢谢你们指出这一点。我已经编辑了我的答案。请原谅我缺乏知识,在这里仍然是菜鸟。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-05
    • 1970-01-01
    • 2012-06-03
    • 2021-08-26
    • 2010-12-11
    • 2017-03-07
    • 2018-03-01
    相关资源
    最近更新 更多