In my theme, to display the featured post I have to add an extra category "featured". Now I have articles showing featured in the url instead of the main category. Any help please? Thanls


It all depends, how these categories are displayed in your theme.

If it's done nicely and with proper use of WP template tags, then that list comes from get_the_category() function (all other functions are using this one).

And at the end of that function you can find

return apply_filters( 'get_the_categories', $categories, $id );

So it's great news, because it means, that you can write your own filter and remove given category from the lists:

function prefix_remove_featured_category_from_post_categories_list( $categories, $id ) {
    // do whatever you want with $categories list
    // for example remove some category from the list
    $categories_to_remove = array(
    ); // Array of categories slug to be remove. Put your slugs in here

    foreach ( $categories as $index => $single_cat ) {

        if ( in_array( $single_cat->slug, $categories_to_remove ) ) {
            unset( $categories[ $index ] ); // Remove the category.

    return $categories;
add_filter( 'get_the_categories', 'prefix_remove_featured_category_from_post_categories_list', 10, 2 );
  • They accepted the answer, so it must've worked, but the question was regarding the URL, not anything in the theme. I suppose the in the permalink is also based on get_the_category(). – Jacob Peattie Jan 9 at 7:54
  • @JacobPeattie commenting wrong answer/question? There is nothing about any URLs in this question ;) – Krzysiek Dróżdż Jan 9 at 7:55
  • "Now I have articles showing featured in the url instead of the main category" – Jacob Peattie Jan 9 at 8:42
  • Exactly - if you use category in urls, then it also is generated based on getting list categories (as all other lists of categories ;)) – Krzysiek Dróżdż Jan 9 at 8:45
  • So the issue with this solution would be that it's hiding the categories from the front-end also, when the question was only about deciding which category to show in the URL. – Jacob Peattie Jan 9 at 8:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.