• Hi,
    i want to set a category-slug just for one category.
    All other categories should be hidden.

    For example:
    – i have 3 categories: /news/, /animals/, /sport/
    – posts with category /news/, sould be shown like these: domain.de/news/post-title/
    – posts with another category (e.g. /animals/ oder /sport/, should be shown like these: domain.de/post-title/.

    Is there any way to do these?
    In german wp-forum no one knows. they just said i can ask in english wp-forum.

    • This topic was modified 4 years, 8 months ago by padylee.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    It can be done with custom rewrite rules. Custom coding is required but even a novice could likely kludge something together from available examples. Set your permalinks to just use the post title, no category terms. Add a rewrite rule that identifies the “news” term in links and rewrites it into a form that WP can use, something like index.php?name=$matches[1] where the post title is captured in the related regexp.

    After adding the needed code, visit the permalinks setting screen to cause the persistent rules to be updated.

    Thread Starter padylee

    (@padylee)

    @bcworkz Thank you!

    It’s good to hear that there’s a possibility. I think I get it.
    The permalink setting is on “post name.”
    But the news URLs can’t be distinguished from the rest of the posts. It’s not like every news item has “news” in the title or anything like that.
    The only thing that distinguishes the posts is the category. Or have I misunderstood something?

    Is it possible that I have to set the permalinks to Custom /%category%/%postname%/? Then maybe I could use add add_rewrite_rule to remove the category for all categories except “news”.

    Does that make sense?

    I found the following in the source code:

    <article id="post-9492" class="post-9492 post type-post status-publish format-standard has-post-thumbnail category-fitness-news tag-duell tag-fitness-influencer tag-johannes-luckas tag-johny-muenster tag-koray-yalcin tag-kreuzheben tag-wettkampf" itemscope itemtype="https://schema.org/Article "47>

    Can I do anything with “category-fitness-news”? This is also included if I leave the permalink setting on “post name”.

    Moderator bcworkz

    (@bcworkz)

    It’s a lot easier to add a special case to watch for than to remove everything but a special case. The regexp for the added rewrite rule would specifically match “/news/” in an URL and only “/news/”. What comes after is presumed to be a post or page slug. If there’s no match for “/news/” a different rewrite rule assumes the first permalink element is a post or page slug. This rule is the default rule established by WP by the permalink setting.

    This could mean you cannot have a post or page slug that is also “news”. Precise behavior depends upon the regexp used and in what order the rules are processed by WP to find a match.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘WordPress Slug just for one Categorie’ is closed to new replies.