• Basically site has woo product page alongwith wp post and migrated all wp post to new location for reduce database load.

    So, concern is: How to redirect all wp post to new location in single setting. Thousands of post, so can’t add all wp post in htaccess or any plugin setting.

    Is any method, so only all wp post redirected to new location?

    Pls guide.

    Thanks.

    • This topic was modified 2 years, 9 months ago by Jan Dembowski. Reason: Moved to Fixing WordPress, this is not an Everything else WordPress topic
Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi @skumar1st

    I think there are many ways: you can take a look at some plugin; you can update your database (have you access to hosting?) and you can develop hook on functions.php to achieve that.

    A plugin: https://wordpress.org/plugins/safe-redirect-manager/

    Thread Starter skumar1st

    (@skumar1st)

    Thanks for quick response.
    I know about “Redirection plugin is available and can do this by insert of every url either plugin or htaccess”
    But could you please confirm code where “all wp post only” redirect to “new location” and rest product page should not redirect?

    Thanks.

    Hi @skumar1st

    The code I don’t now, I have to search exactly and tell you. But I have searched now and found this:

    https://wordpress.org/plugins/quick-pagepost-redirect-plugin/

    It seems to me this plugin can specify the post type (post) and redirect to new URL. What do you think to test it?

    You could use wp_redirect().

    If you just want all posts to redirect to one location, use the code below. You can add it to your functions.php or use the Code Snippets plugin.

    add_action('template_redirect', 'wpsf_redirect_posts');
    function wpsf_redirect_posts()
    {
    	if (is_singular('post')) {
    		wp_redirect('https://www.example.com/', '301');
    		exit;
    	}
    }

    Or, if you want each post to redirect to a different location, you’ll need to add some logic specific to your needs. Here’s a bit of code that might show you how that would work.

    add_action('template_redirect', 'wpsf_redirect_posts');
    function wpsf_redirect_posts()
    {
    	if (is_singular('post')) {
    		$post_slug = get_queried_object()->post_name;
    		wp_redirect('https://www.example.com/' . $post_slug, '301');
    		exit;
    	}
    }
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘All Post redirect to another location’ is closed to new replies.