I have category called "us".

I am trying to change link structure from :




I have inserted code in functions.php :

function change_permalinks($permalink) {
$permalink = str_replace("us/", "", $permalink);
return $permalink;

add_filter( 'post_link', 'change_permalinks', 10, 4);

This changes links on my wordpress website as expected. Problem is when I click on link I am getting

404 not found exception

Problem is that wordpress still expects old link structure. Any help ?

  • You need a rewrite rule, all you've done is alter permalink output, which isn't related to parsing incoming requests. However, you will find this is not so simple, as your desired structure clashes with the page post type.
    – Milo
    Apr 23, 2014 at 14:56
  • I have tried creating rewriteRule in htaccess file without success. I have got same behavior. I have rewritten URL so user is redirected to another path but I want to change links internally. Apr 24, 2014 at 7:46
  • WordPress has an internal rewrite system, search here for add_rewrite_rule. But again, what you want to do is not easy, how will WordPress know you want a post and not a page?
    – Milo
    Apr 24, 2014 at 14:22
  • As I can see post and page are basically same and they are saved in same table in Wordpress. For me it's same post or page if I get URI structure that I want. Apr 25, 2014 at 8:53
  • They're the same except for post type column, which is why your current code returns a 404, WordPress is looking for a page, not a post. If you override that rule, WordPress will always look for a post, and pages will return 404.
    – Milo
    Apr 25, 2014 at 14:56

1 Answer 1


This plugin might help you.


It removes category slug

  • I don't need to remove category slug and I don't need to use plugin to do a simple task. Apr 23, 2014 at 12:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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