Wordpress 如何向comment\u reply\u link函数生成的comment-reply链接添加额外的css类?
因此,在WordPress评论回复部分中添加css类存在问题 评论回复链接功能在回复按钮中添加css类评论回复链接。有没有办法将新的css类添加到评论回复链接中Wordpress 如何向comment\u reply\u link函数生成的comment-reply链接添加额外的css类?,wordpress,Wordpress,因此,在WordPress评论回复部分中添加css类存在问题 评论回复链接功能在回复按钮中添加css类评论回复链接。有没有办法将新的css类添加到评论回复链接中 我知道我可以使用jquery来实现这一点,但是有没有办法不使用jquery来实现这一点呢?您可以在评论回复链接功能中添加一个过滤器 function comment_reply_link_filter($content){ return '<div class="yourclass">' . $content . '
我知道我可以使用jquery来实现这一点,但是有没有办法不使用jquery来实现这一点呢?您可以在
评论回复链接功能中添加一个过滤器
function comment_reply_link_filter($content){
return '<div class="yourclass">' . $content . '</div>';
}
add_filter('comment_reply_link', 'comment_reply_link_filter', 99);
函数注释\回复\链接\过滤器($content){
返回“.$content.”;
}
添加过滤器('comment\u reply\u link','comment\u reply\u link\u filter',99);
我知道它不直接在元素上,但现在您可以使用.yourclass>对元素进行样式设置。注释回复链接
这样,我将类添加到注释回复链接
<?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”属性中。谢谢您的回答:)实际上,我想将引导按钮集成到WordPress评论回复部分。所以,我认为上述解决方案不是一个好的选择。如果您知道任何其他方式,那么将不胜感激。再次感谢你!如果你替换返回“”,你能发布你得到的吗$内容",代码>用于返回变量转储($content)代码>?也许你可以解析输出并尝试添加你的类。在使用你的第一个代码后,我得到了这个错误。致命错误:在用返回变量转储($content)替换第二行后,无法在第115行的E:\xampp\htdocs\wp\wp content\themes\raw\inc\template tags.php:115)中重新声明E:\xampp\htdocs\wp content\themes\raw\inc\template-tags.php中声明的注释\回复\链接\过滤器();另一个错误显示为字符串(162)“Reply”致命错误:无法重新声明注释\u Reply\u link\u filter\u test()(以前在E:\xampp\htdocs\wp\wp content\themes\raw\inc\template tags.php:115中声明)在第115行的E:\xampp\htdocs\wp\wp content\themes\u raw\inc\template-tags.php中,如果用addclass\u comment\u reply\u link\u filter
替换?确保在add_filter函数中也替换名称。