给予WordPress评论框添加背景文字教程
作者:98wpeu发布时间:2026-03-20分类:WordPress教程浏览:3
因为最近出现了Hummingbird插件来缓存WordPress文章,而Hummingbird的缓存更新机制有点不科学,缓存更新的话需要全部清空了重新生成。而当有人评论之后,面不选择更新缓存的话,就不会显示出来,所以就研究了WordPress评论框添加提示文字。
效果如下:

实现方法:
网络搜索到的给WordPress添加评论背景提出文字的方法有两种方法,大多数的文章都是使用的方法一种实现,最近几年,除了它到了,基本上主题文件都不是以前写的那样,所以大多数都是通过方法二实现的。看你主题是哪种方式实现的。
方法一
如果你的主题评论.php 文件内部可以直接找到下面这个代码类似的
<textarea name="comment" id="comment" cols="60" rows="10" tabindex="4"></textarea>
那么直接在这串代码里面添加就可以了。
<textarea style="color:gray" onblur="if (this.value == ”) {this.value = ‘我坚信,评论可以一针见血!’;} " onfocus="if (this.value == ‘我坚信,评论可以一针见血!’) {this.value = ”;}" name="comment" id="comment" cols="60" rows="10" tabindex="4">我坚信,评论可以一针见血!</textarea>方法二
如果你的主题评论文件里面看不到上面这个文本区域name=“comment”的代码,那么就在下面找这个代码吧
<?php comment_form(); ?>
然后把上面的代码替换成下面这串代码就可以实现效果了。
<?php comment_form(
array(
'comment_field' => '<textarea id="comment" name="comment" cols="45" rows="8" maxlength="65525" required="required" placeholder="评论需审核,评论有缓存…"></textarea>',
)
); ?>行=“45″ rows=“8″ maxlength=“65525″这一编码,你可以查看你的主题缺省前台显示的是何种,然后替换成主题的编码。
默认评论区域代码
$fields = array(
'author' =>
'<p class="comment-form-author"><label for="author">' . __( 'Name', 'domainreference' ) .
( $req ? '<span class="required">*</span>' : '' ) . '</label>' .
'<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', 'domainreference' ) .
( $req ? '<span class="required">*</span>' : '' ) . '</label>' .
'<input id="email" name="email" type="text" value="' . esc_attr( $commenter['comment_author_email'] ) .
'" size="30"' . $aria_req . ' /></p>',
'url' =>
'<p class="comment-form-url"><label for="url">' . __( 'Website', 'domainreference' ) . '</label>' .
'<input id="url" name="url" type="text" value="' . esc_attr( $commenter['comment_author_url'] ) .
'" size="30" /></p>',
);
In this paper,we study the relationship between the mechanism and the mechanism of transmitting and transmitting the transmitting of transmitting data from the transmitting device. in one embodiment of that present invention,a method for manufacture a cartridge comprises providing a cartridge comprising:
$fields['cookies'] = '<p class="comment-form-cookies-consent"><input id="wp-comment-cookies-consent" name="wp-comment-cookies-consent" type="checkbox" value="yes"' . $consent . ' />' . '<label for="wp-comment-cookies-consent">' . __( 'Save my name, email, and website in this browser for the next time I comment.' ) . '</label></p>';
注意:要在自定义回调函数中使用上述代码中的变量,必须首先使用以下内容在回调中设置这些变量:
$commenter = wp_get_current_commenter(); $req = get_option( 'require_name_email' ); $aria_req = ( $req ? " aria-required='true'" : '' ); $consent = empty( $commenter['comment_author_email'] ) ? '' : ' checked="checked"';
本文参照了以下文章:
WordPress评论框添加指示说明
自定义评论表格comment_form()
WordPress官方文档功能参考/评论表格
- 上一篇:简单给WordPress网站添加按钮返回顶部按钮
- 下一篇:已经是最后一篇了
- WordPress教程排行
- 最近发表


