WordPress 私密或受保护的文章标题会有一个前缀,比如《私密:This is a sample post》,这对于我来说是无法接受的。把这前缀去掉,将以下代码放到主题的 functions.php 中即可。
//remove title prefix of private or protected posts
function title_format($content) {
return '%s';
}
add_filter('private_title_format', 'title_format');
add_filter('protected_title_format', 'title_format');
当然,也可以自定义标题前缀,修改上面函数中的返回格式就可以,比如:
return 'Members Only: %s';
既然去掉了标题前缀,那么怎么区分私密文章呢?我的解决办法是在文章发布日期后增加一个标签。分别在文章模版和列表模版的日期后,增加以下代码:
Private"; } ?>
样式参考如下(本主题使用了 Genericons 字体,请自行在你使用的图标字体选择合适图标):
/*private posts icon*/
.post_private::before {
padding-right: 3px;
padding-bottom: 4px;
content: '\f470';
display: inline-block;
font-family: Genericons;
font-size: 16px;
font-style: normal;
font-weight: 400;
font-variant: normal;
line-height: 1;
vertical-align: middle;
-webkit-font-smoothing: antialiased;
}
效果图:

还没玩过带密码的文章
我偶尔有些私密的
这方法不错,改天也折腾上。