在 wordpress 博客上全局隐藏(不删除)类别名称

Hide (not remove) category name globally on wordpress blog

我试图在我的整个 wordpress 博客上隐藏一个特定的类别名称(例如称为 "Featured")。请注意,我不想排除属于该特定类别的 post,我只想防止实际类别名称出现在任何地方,它应该是不可见的。

我发现了一个代码片段,我将其放入 functions.php,实际上它完全符合我的要求,但它只是隐藏了 post 元部分中的类别名称,它并没有对仍然显示类别名称的第三方插件有任何影响。你能帮忙让这个适用于特定的插件吗?

function.php 中用于隐藏类别名称的代码:

function the_category_filter($thelist,$separator=' ') {
if(!defined('WP_ADMIN')) {

    $exclude = array('featured');
    $cats = explode($separator,$thelist);
    $newlist = array();
    foreach($cats as $cat) {
        $catname = trim(strip_tags($cat));
        if(!in_array($catname,$exclude))
            $newlist[] = $cat;
    }
    return implode($separator,$newlist);
} else
    return $thelist;
}
add_filter('the_category','the_category_filter',10,2);

插件的功能如下所示:

private function generate_post_categories( $post ) {

    // Setting up category list string.
    $post_cat_string = '';

    // Setting up category list.
    $post_cat_list = '';

    // Fetching post category prefix  with WPML support.
    $post_category_prefix = ($this->icl_t) ? icl_t('ORP Post Category Prefix', 'post-category-prefix–' . $this->widget_id, $this->widget_args['post_category_prefix'] ) : $this->widget_args['post_category_prefix'];

    // Checking for post category PREFIX.
    if ( !empty( $this->widget_args['post_category_prefix'] ) ) {

        // Building post category PREFIX HTML.
        $post_cat_string .= esc_html( $post_category_prefix );
    }

    // Retrieving categories array.
    $orp_categories = get_the_category( $post->ID );

    // Checking if "post category link" option is on.
    if ( 'yes' == $this->widget_args['post_category_link'] ) {

        // Looping through categories array.
        foreach( $orp_categories as $orp_cat ) {

            // Fetching the current category link.
            $orp_category_link = get_category_link( $orp_cat->cat_ID );

            // Building HTML link atts.
            $linkatts = array(
                'href'  => $orp_category_link,
                'title' => $orp_cat->cat_name
            );

            // Building category link HTML.
            $post_cat_list .= $this->orp_create_tag( 'a', $orp_cat->cat_name, $linkatts ) . esc_html( $this->widget_args['post_category_separator'] );
        }

    } else {

        // Looping through categories array.
        foreach( $orp_categories as $orp_cat ) {

            // Filling categories list.
            $post_cat_list .= $orp_cat->cat_name . esc_html( $this->widget_args['post_category_separator'] );
        }
    }

    // Right trimming the last category separator on the category list.
    $post_cat_string .= rtrim( $post_cat_list, esc_html( $this->widget_args['post_category_separator'] ) );

    // Returning the post category HTML.
    return $this->orp_create_tag( 'div', $post_cat_string, array( 'class' => 'orp-post-category' ) );

你能不能试试改一下这部分:

// Looping through categories array.
foreach( $orp_categories as $orp_cat ) {

收件人:

// Looping through categories array.
foreach( $orp_categories as $orp_cat ) {
  if($orp_cat->cat_name == 'Featured') {
    continue;
  }

如果类别名称等于 "Featured",则应跳过循环。