有没有用Astra 这个WordPress主题的,怎么把首页右侧评论里评论者的链接去掉
有没有用Astra 这个WordPress主题的,怎么把首页右侧评论里评论者的链接去掉?让这个评论者链接只显示在文章页面评论里 关于WordPress的Astra主题中评论者链接的隐藏问题,这里提供三种专业解决方案:
1. CSS定位隐藏方案(推荐):
在WordPress后台「外观」→「自定义」→「附加CSS」添加:
/* 首页评论链接隐藏 */
.home .comment-metadata a:first-child,
.home .comment-author a {
display: none !important;
}
/* 文章页保留链接 */
.single-post .comment-author a {
display: inline-block !important;
}
2. 函数过滤方案(需子主题):
在子主题functions.php中添加:
add_filter( 'get_comment_author_link', function( $return, $author, $comment_ID ) {
if ( is_home() || is_front_page() ) {
return strip_tags( $author );
}
return $return;
}, 10, 3);
3. 模板覆盖方案(适合开发者):
创建子主题后复制以下模板文件:
/wp-content/themes/astra/inc/comment-template.php
找到`get_comment_author_link()`函数调用处,修改为:
if( !is_front_page() ) {
printf( '<div class="comment-author vcard">%s</div>', get_comment_author_link() );
} else {
echo '<div class="comment-author vcard">'.get_comment_author().'</div>';
}
注意:具体选择方案需根据站点技术架构:
- 若使用页面构建器生成首页,推荐方案1+增加构建器容器类名
- 若使用AJAX加载评论,推荐方案2+增加is_admin()判断
- 若需要SEO优化,建议配合schema微数据调整
建议实施步骤:
1. 创建子主题备份
2. 优先尝试CSS方案
3. 清除缓存后测试效果
4. 若无效再采用函数方案
针对Astra主题的特殊情况:该主题在移动端可能会合并显示元数据,建议增加响应式控制:
@media (max-width: 768px) {
.home .comment-metadata {
display: none;
}
}
-- 本回答由 人工智能 AI智能体 生成,内容仅供参考,请仔细甄别。
页:
[1]