【问题标题】:Can't remove website field in comment form (Wordpress 3.0)无法删除评论表单中的网站字段(Wordpress 3.0)
【发布时间】:2010-08-01 09:58:49
【问题描述】:

我按照this site 中的说明进行操作,但comment.php 中没有这样的代码。我正在使用Starkers 主题,但里面似乎没有任何东西可以控制网站字段。

它现在在 Wordpress 3.0 中是否处于 nw 位置?

它在哪里?

【问题讨论】:

    标签: wordpress forms web


    【解决方案1】:

    评论表单由comment_form() function 控制。如果你想改变它的输出,你有两个选择:

    1. 在调用时更改$fields 参数以删除comment_author_url
    2. 在主题的functions.php 中过滤函数的输出。

    字段参数

    $your_fields =  array(
        'author' => '<p class="comment-form-author">' . '<label for="author">' . __( 'Name' ) . '</label> ' . ( $req ? '<span class="required">*</span>' : '' ) .               '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /></p>',
        'email'  => '<p class="comment-form-email"><label for="email">' . __( 'Email' ) . '</label> ' . ( $req ? '<span class="required">*</span>' : '' ) . '<input id="email" name="email" type="text" value="' . esc_attr(  $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /></p>',
    );
    comment_form(array('fields' => $your_fields));
    

    过滤器

    function your_comment_form_fields($the_form_fields){
        // code to remove the author field from $the_form_fields
        return $the_form_fields;
    }
    add_filter('comment_form_default_fields', 'your_comment_form_fields');
    

    【讨论】:

      【解决方案2】:

      转到 wp-content\themes\suffusion\cmets.php 文件

      suffusion是我的主题名称,你应该去你各自的主题文件夹

      找到这段代码

      comment_form(apply_filters('suffusion_comment_form_fields', array(
              'fields' => array(
                  'author' => $author_field,
                  'email' => $email_field,
              //  'url' => $url_field,  // comment this field 
              ), 
      

      然后评论 url 字段。它在我的情况下工作。

      您可以查看site 以供参考

      【讨论】:

        【解决方案3】:

        下面的帖子解释了如何从评论表单中删除网站字段。由于它不特定于主题或核心文件,因此它应该适用于所有最新和未来的 Wordpress 版本。

        http://techhacking.com/2011/02/04/stop-comment-form-spam-in-the-website-field/

        【讨论】:

          【解决方案4】:

          我也在使用 Starkers,但无法通过在 fields 参数中不传递“url”键或空“url”键来删除网站字段。这是因为 Starkers 在functions.php 中使用自己的自定义函数来对comment_form_default_fields 应用过滤器。通过以下方式检查修改评论表单:

          function starkers_fields($fields) 
          

          它正在做:

          add_filter('comment_form_default_fields','starkers_fields');
          

          现在我可以更轻松地设置标签和所需星号的样式。所需的星号没有包装元素,这使得对齐样式成为问题。

          【讨论】:

            【解决方案5】:

            请将此代码添加到您主题的functions.php中

            function crunchify_disable_comment_url($fields) { 
            unset($fields['url']);
            return $fields;
            }
            add_filter('comment_form_default_fields','crunchify_disable_comment_url');
            

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2011-12-05
              • 1970-01-01
              • 2020-09-25
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              相关资源
              最近更新 更多