回复链接
我假设您的回复链接如下所示:
<a class="comment-reply-link" href="/2013/12/29/hello-world/?replytocom=32#respond"
onclick="return addComment.moveForm(\'comment-32\', \'32\', \'respond\', \'1\')">Reply</a>
和取消回复链接:
<a rel="nofollow" id="cancel-comment-reply-link"
href="/2013/12/29/hello-world/#respond" style="">Cancel reply</a>
Javascript方法
addComment.moveForm
定义于
/wp-includes/js/comment-reply.min.js
.
演示插件:
要隐藏评论回复的额外主题字段,您可以尝试检查
replytocom
获取非Javascript案例的参数,并钩住Javascript案例的click事件。
这是一个演示Comment Subject 插件:/wp-content/plugins/comment-subject/comment-subject.php
:
<?php
/**
* Plugin Name: Comment Subject
*/
/**
* Add extra Subject comment field when there is no replytocom in the url
*/
function additional_fields () {
$url_query = parse_url( $_SERVER[\'REQUEST_URI\'], PHP_URL_QUERY );
if( FALSE === stripos( $url_query, \'replytocom\' ) )
{
echo \'<p class="comment-form-subject">\'.
\'<label for="subject">\' . __( \'Your subject\' ) . \'</label>\'.
\'<input id="subject" name="subject" type="text" size="30" tabindex="5" /></p>\';
}
}
add_action( \'comment_form_logged_in_before\', \'additional_fields\' );
add_action( \'comment_form_before_fields\', \'additional_fields\' );
/**
* Add jQuery and load the custom "script.js"
*/
function custom_scripts()
{
wp_enqueue_script( \'jquery\' );
wp_enqueue_script( \'my-comment-subject\',
plugins_url( \'js/script.js\' , __FILE__ ),
array( \'jquery\' ),
\'1.0.0\',
TRUE
);
}
add_action( \'wp_enqueue_scripts\', \'custom_scripts\' );
添加文件的位置
/wp-content/plugins/comment-subject/js/script.js
包含:
jQuery(document).on( \'click\', \'a.comment-reply-link\', function( event ) {
jQuery(\'p.comment-form-subject\').hide();
});
jQuery(document).on( \'click\', \'a#cancel-comment-reply-link\', function( event ) {
jQuery(\'p.comment-form-subject\').show();
});