1

My permalinks are set like:

http://myblog.com/%category%/%postname%/

Everything works fine.

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

http://myblog.com/%postname%/

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. – websupporter Apr 16 '15 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 '15 at 21:30
0

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

index.php?page_id=

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.