My permalinks are set like:


Everything works fine.

But I am looking for a way to set the permalink like the following for only some posts (10-11 posts).


I want this because I am merging two WordPress websites and I don't want to loose the posts of the other website which are already published on Facebook etc with the old permalink structure.

  • Instead of a WordPress solution I would recommend altering the htaccess for these few posts and redirect them. Apr 16, 2015 at 20:57
  • @websupporter Facebook doesn't follow redirects, once a URL is in graph, it can't be changed without losing all prior activity.
    – Milo
    Apr 16, 2015 at 21:30

1 Answer 1


You could use the Rewrite API. Since you have a fixed set of posts you could do the following:

 add_action( 'init', 'rewrite_old_slugs' );
 function rewrite_old_slugs(){
    $post_slugs = array(
        'post-1' => 1,
        'post-2' => 2 

    foreach( $post_slugs as $slug => $new_id )
        add_rewrite_rule( $slug . '?$', 'index.php?p=' . $new_id, 'top' );

I've created a post_slugs array where the array keys are the old slugs and the array values are the post ids.

If you go this way, you have to go to Settings > Permalinks and hit the update-button, so the rules are active.

This solution works for posts. If you need it for pages, you need to rewrite the URLs to


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.