• Hello,

    I hope I’m in the right place for this. I have searched around for this exact question and while I’ve found tangential discussions, none were looking for this exact behavior. Apologies if I have missed any!

    BACKGROUND
    I set up my website years ago with the permalink structure:

    /%category%/%postname%/

    but didn’t realize that it’s not ideal to do so when you have posts assigned to multiple categories. This results in posts being available at multiple URLs (default behavior for this setup from my understanding).

    My concern is not with selecting a primary/canonical URL as I have Yoast handling this. My issue is that because you can access a post at multiple URLs, this causes problems with page caching/purging, and Google Analytics given they are treated as “separate” posts.

    So, for example if you were to visit:
    mydomain.org/category1/post-slug
    mydomain.org/category2/post-slug

    The URL in the address bar will stay the same as what you visited. Even if category1 is the primary/canonical, if you visit with /category2/ it will remain that in the address bar. Again this is standard behavior, from what I understand. However, this leads to that post being cached separately within page caching and then not purge/update properly. It also means Google Analytics logs it as a different post.

    DESIRED BEHAVIOR (IF POSSIBLE?)
    I’m hoping to find a way to have WordPress redirect/defer (maybe not correct terms) to the primary/canonical whenever you try to visit another assigned category.

    This already happens if you replace the category with a category on my website that the post is not in. So, for example, let’s say for the example above, the post is in “category1” and “category2” but not “category3”.

    In that case, if you visit
    mydomain.org/category3/post-slug

    You are brought to the primary/canonical at:
    mydomain.org/category1/post-slug

    Is there a way to achieve this even with non-primary/non-canonical assigned categories? That way no one ever ends up on the non-canonical/non-primary.

    _____________________

    POSSIBLE ALTERNATIVES??
    1. I have considered going through and assigning only a single category to my posts, however I use categories for my site’s “browse” navigation and archives and most posts legitimately belong in multiple categories for that functionality.

    2. Another thought was to change my permalinks to not have categories, but from what I’ve read this is strongly not advised from an SEO standpoint (and for existing links around the web)

    3. A third option that’s seems messy was to create a custom “category substitute” taxonomy that I’d use purely for my “browse” page for user filtering. That way I could assign posts to multiple “category substitutes” for the filtering, but only assign one “true” WordPress category for the permalink. The issue with this, though, is that the posts that are assigned to multiple categories would no longer be on those category archives. (And this may be a horrible idea!)

    _____________________

    I hope I’ve made sense. If I can further clarify, please let me know. I would greatly appreciate any input!

    Thank you so very much

Viewing 2 replies - 1 through 2 (of 2 total)
  • If you want only show in category1,
    But you set post for category1 and category2.

    What about use redirect category2 to category1
    so it will only show on category1
    Search engine will also detect that there is only one post.

    When people visit it the main post is only on category1.
    the problem is then need do a lot redirection if have a lot post.

    I know it’s a bad idea,
    but here’s one solution I understand.

    Hope this help.

    Thread Starter small_fork

    (@emilymoran84)

    Adam,

    Thank you for the reply. Unfortunately, that solution won’t work properly, I don’t believe. I do have a ton of posts, and would need to create a large amount of redirect. I am concerned about doing so being problematic for reasons I’m not even sure about. I do know that having a lot of redirects isn’t ideal.

    Google/search engines already know there is only one post due to the canonical being correctly declared by Yoast.

    I would be interested to know how problematic this approach is… But I am really hoping there is a way to programmatically achieve this.

    Appreciate you weighing in!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to always direct to primary/canonical URL with posts in multiple categories’ is closed to new replies.