post_class()
是一个包裹get_post_class()
.
尝试以下挂钩post_class
这是从get_post_class()
在内部wp-includes/post-template.php
:
add_filter(\'post_class\', \'filter_post_class\', 10, 3);
function filter_post_class($classes, $class, $post_id) {
$temp = implode(\' \', $classes);
$temp = preg_replace(\'/\\s\\btag\\-\\w*\\b/i\', \'\', $temp);
return explode(\' \', $temp);
}
或者(
RECOMMENED):
add_filter(\'post_class\', \'filter_post_class\', 10, 3);
function filter_post_class($classes, $class, $post_id) {
$classes = array_filter($classes, function($class_name){
// use !== 0 to ensure we match tag- at begining of string
return strpos($class_name, \'tag-\') !== 0;
});
return $classes;
}
另一种可能存在风险的替代方法是:
add_filter(\'get_the_tags\', \'filter_get_the_tags\');
function filter_get_the_tags() {
return array();
}
虽然使用这种方法时,应该在回调中考虑一些条件逻辑。
我之所以这样说是因为只有其他函数(就核心WP而言)调用get_the_tags()
是wp-includes/feed.php
特别是get_the_category_rss()
.