0

I have a blog and I'm changing it to a new theme.

Old one has structure blog.com/postname. New one has newblog.com/posts/postname.

I want to redirect ONLY posts from old blog to this new structure, if possible without a plugin.

Pages, archives and everything else that is not a single post will should remain newblog.com/postname structure.

Any ideas?

  • From your question, you're mentioning the two domains. blog.com & newblog.com. Technically, you'll need to 301 every URL, not just for posts but pages & archives too. And, if you only need to move posts - well, then there should be a new approach. And, for that you should ask here: webmasters.stackexchange.com – tushonline Dec 11 '15 at 8:14
0

You'll have to modify your old theme's function.php. Add the following code:

function redirect_posts() {
    global $post;
    if ($post->post_type=='post') {
        return header('location:http://newblog.com/posts/'.$post->post_name);
    }
}
add_action('wp', 'redirect_posts');

The if codintion will check if the page what's currently viewed is a post and it returns a header redirect to the new blog based on the old blog post's slug.

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.