How to redirect a post having a Draft status to the WordPress home page

How to redirect a post having a Draft status to the WordPress home page

In WordPress, managing the status of your posts is crucial for maintaining an organized and user-friendly website. If you find yourself needing to redirect a post having a Draft status, perhaps to guide your visitors to the homepage, this comprehensive guide will walk you through the process step by step. Discover effective techniques for redirecting draft posts and optimizing your site’s navigation seamlessly.

Why it is important to redirect a post having a Draft status to the home page

For some reason, if someone can get the post URL and tries to access it, the site will show 404 or a page not found error. This will not only create a bad impression for search engines but will also affect the site’s SEO. To resist this 404 error, we can simply redirect a post having a Draft status to the home page of the WordPress website.

There are usually 3 types of post status offered by WordPress:

  1. Draft
  2. Pending Review
  3. Published

You may wish to redirect the user to either the home page or any other page on your website.

posts-draft-status

In this article, we will see how to redirect (301) posts having a draft status. We will cover both redirections to the home page or any other page.

We will use wp_redirect() function to perform redirection.

Redirect a post having a Draft status to the home page

In your child theme, open the single.php file (or create it if does not exist already). Or if you are using custom posts then open your_custom_post-single.php file and copy and paste the following code:

<?php
	if($post->post_status == 'draft') {
	    wp_redirect( home_url() . "/", 301 );
	}
?>

The above code redirect a post having a Draft status to the home page.

Redirect a post having a Draft status to the other page

Open single.php file, or if you are using custom posts then open your_custom_post-single.php file and copy and paste the following code:

<?php
	if($post->post_status == 'draft') {
	    wp_redirect( home_url() . "/some-page/", 301 );
	}
?>

The above code redirects a post having a Draft status to a page having the name “some-page”.

The Redirection plugin method

If you are not comfortable writing the code, another option for applying redirection is to use plugins. Redirection is a popular and user-friendly plugin that allows you to set up redirects effortlessly. Install and activate the plugin from the WordPress Plugin Repository.

wordpres redirection plugin

1) Install a Redirection Plugin

To simplify the redirection process, consider using a WordPress plugin. “Redirection” is a popular and user-friendly plugin that allows you to set up redirects effortlessly. Install and activate the plugin from the WordPress Plugin Repository.

2) Configure the Redirection

Once the Redirection plugin is activated, go to “Tools” and select “Redirection” from the WordPress admin menu. Add a new redirection by entering the source URL, which is the URL of your draft post, and set the target URL as the homepage. Save the changes.

wordpres redirectio plugin

3) Additional Considerations

  • Regularly Review and Update Redirects: As your content evolves, review and update your redirects accordingly. This ensures that your redirection strategy aligns with the current structure and goals of your website.
  • Communicate Changes Internally: If your website has multiple contributors, communicate any changes in the redirection strategy. This helps maintain a cohesive approach to managing draft posts and ensures everyone is on the same page.

Test the Redirection

It’s crucial to test the redirection to ensure it works as expected. Open a new incognito window in your browser and enter the URL of the draft post. You should be automatically redirected to the homepage. If the redirection is successful, you’ve effectively redirected a post having a Draft status.

Conclusion

To redirect a post having a Draft status in WordPress is a valuable technique for refining your website’s content management and enhancing the overall user experience. By leveraging the power of the Redirection plugin, you can effortlessly guide users away from draft content to the homepage, where they can access polished and published materials. Implementing this redirection strategy contributes to a more organized and user-friendly WordPress site. Optimize your content management practices today for a more streamlined and effective website.

Related Posts