Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Wordpress中向注释表单添加类_Wordpress_Comments - Fatal编程技术网

在Wordpress中向注释表单添加类

在Wordpress中向注释表单添加类,wordpress,comments,Wordpress,Comments,我想向表单中添加一个类,而不是表单项。我已经看过了,但是没有提到在表单中添加类。您只需编辑single.php并包装: <?php comments_template(); ?> 在课堂上。比如: <div class="myClass"> <?php comments_template(); ?> </div> 更新: Wordpress最终支持将类添加到评论表单的可能性。请参见以获取示例 我过时的答案: 由于Wordpress仍然不支

我想向表单中添加一个类,而不是表单项。我已经看过了,但是没有提到在表单中添加类。

您只需编辑single.php并包装:

<?php comments_template(); ?>

在课堂上。比如:

<div class="myClass">
<?php comments_template(); ?>
</div>

更新

Wordpress最终支持将类添加到评论表单的可能性。请参见以获取示例


我过时的答案

由于Wordpress仍然不支持此选项,因此我制定了以下解决方案:

<?php
    ob_start();
    comment_form();
    echo str_replace('class="comment-form"','class="comment-form your-custom-class"',ob_get_clean());
?>

自wordpress版本4.1(2014年12月)以来,comment_form函数允许为submit按钮指定类属性

Php代码:

$comments_args = array('class_submit' => 'btn btn-default');
comment_form($comments_args);
生成的HTML按钮代码:

<input name="submit" type="submit" id="submit" class="btn btn-default" value="Submit" />

有关参考信息,请参阅以下中的相关票据:

WordPress 4.4.0引入了'class\u form'[…]参数

所以你会这样做:

// Output the comment form with a custom class:
comment_form ( array( 'class_form' => 'my_custom_class' ) );

三思而后行 我更喜欢使用钩子:

/**
 * Callback function for the `comment_form_defaults` filter hook
 *
 * @param Array $defaults Defaults.
 * @return Array          Defaults modified.
 */
function se_8476425_modify_comment_form_defaults( $defaults ) {
    $defaults[ 'class_form' ] = 'class1 class2 class3';
    return $defaults;
};

add_filter( 'comment_form_defaults', 'se_8476425_modify_comment_form_defaults' );

此解决方案更通用,因为您可以使用它修改默认功能行为和您不“拥有”的主题。

您可以使用此筛选器轻松修改coment表单的提交按钮的代码:

function custom_submit_comment_form( $submit_button ) {
  return '<input name="submit" type="submit" id="submit" class="btn btn_2" value="Laisser un commentaire" />';
}
add_filter( 'comment_form_submit_button', 'custom_submit_comment_form' );
功能自定义提交评论表单($submit\u按钮){
返回“”;
}
添加过滤器(“评论表单提交按钮”、“自定义提交表单”);

这很简单,但绝对精彩。我们可以替换多个类吗?怎么做?嗨,奈杰尔,我建议你使用钩子作为方法。这将覆盖注释表单的所有已定义类。关于如何使用id=“respond”?@raisson将类添加到注释包装器中的任何想法在注释上提问都是不切实际的。请使用此链接提出新问题。