所以,这里是在WordPress评论回复部分添加css类的问题
comment_reply_link函数在回复按钮中添加css类comment-reply-link。有什么方法可以将新的 css 类添加到 comment-reply-link 吗?
我知道我可以使用 jquery 来做到这一点,但是有什么方法可以做到这一点而不使用 jquery?
这样,我将 class 添加到 comment-reply-link
<?php
$myclass = 'icon-share-alt';
echo preg_replace( '/comment-reply-link/', 'comment-reply-link ' . $myclass,
get_comment_reply_link(array_merge( $args, array(
'add_below' => $add_below,
'depth' => $depth,
'max_depth' => $args['max_depth']))), 1 );
?>
截图:
结合其他几个答案
function custom_comment_reply_link($content) {
$extra_classes = 'button button--small button--white';
return preg_replace( '/comment-reply-link/', 'comment-reply-link ' . $extra_classes, $content);
}
add_filter('comment_reply_link', 'custom_comment_reply_link', 99);
这会将
$extra_classes
的值添加到所有回复链接的“class”属性。
您可以向
comment_reply_link
功能添加过滤器。
function comment_reply_link_filter($content){
return '<div class="yourclass">' . $content . '</div>';
}
add_filter('comment_reply_link', 'comment_reply_link_filter', 99);
我知道它不是直接在元素上,但您现在可以使用
.yourclass > .comment-reply-link
设置元素的样式。