0

My current permalink structure is  /%category%/%postname%/  which produce urls as:
(category_base removed using "FV Top Level Categories" Plugin)

category: example.com/class-10/science/    ◀▬ SLASH is GOOD for directories & ↙ parent pages
    page: example.com/legal/

    post: example.com/class-10/science/ch-1-atoms/    ◀▬ but BAD for single_post, ↖ child pages &
    page: example.com/legal/terms/
    page: example.com/about/    ◀▬ standalone pages

So, I want to
keep TRAILING SLASH "/" on:

  • categories and child categories
  • parent pages

remove TRAILING SLASH "/" on:

  • single_posts
  • standalone page (who don't have any child pages)
  • child pages

AND "301" Redirect  "/"  version of these ↖ pages to NON  "/"  version pages

0

After SO MANY research, I found a Great Simple solution via https://stackoverflow.com/a/54251892/10403689 (vote this ⬆UP⬆)

Your Permalink Structure should be: /%category%/%postname%/

function no_post_slash( $string, $type ){
    if($type == 'single')
        $string = untrailingslashit($string);
   return $string;
}
add_filter('user_trailingslashit', 'no_post_slash', 70, 2);

BUT this is only working on single_post not pages

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.