Support » Fixing WordPress » Prevent direct access to child category

  • Hi,

    I have a website that is essentially an online newspaper/magazine, where there are categories and within them child categories.

    I’ve realised that visitors can access the child categories without going via the parents, and I’m wondering if there’s any way to prevent this as it alters the look of the posts.

    For example, is the preferred URL, but the same thing can also be accessed via and the styling is affected.

    Is there anything I can do (preferably a future-proof overall method rather than category-specific codes) to redirect the readers to the correct path?

    I’ve tried if ( $post->post_parent == 'entertainment' ) {$entertainment == get_the_category(); header( 'Location: ..\entertainment/'.$entertainment);} but it causes redirect loops – and I have a few other parent and child categories that need addressing too.

    Is there possibly even a .htaccess solution? I tried a 301 without luck, but I’m no expert at either PHP or altering .htaccess files.

    Any suggestions much appreciated.

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Prevent direct access to child category’ is closed to new replies.