Tutorial: Allow Public Preview of a Post in WordPress

DEVELOPMENT

Tutorial: Allow Public Preview of a Post in WordPress

Want to allow someone to read an unpublished post in WordPress? This Tutorial will show you how to create a Public Post Preview in minutes.

Previewing your own WordPress post is an essential part of any editing process.  You need to see how it looks, whether the formatting is correct, and  that it all makes sense.  Unfortunately, the WordPress core installation requires that you log in to see the post preview.

However, what happens when you want a third-party to check over your post before it is published?  Perhaps you need a specialist opinion, or want someone to give you a review, or check the grammar or spelling.  The old way was to create a user for them to log in, allowing them to preview the post after which deleting the user account again.  This is an unnecessarily complicated process, that thanks to some hard work by a developer called Dominik Schilling we are now able to access a Preview post in WordPress Publicly.

Public Post Preview Plugin

Dominik Schilling put his mind to the problem and created a plugin called "Public Post Preview," which is freely available in the WordPress repository.  At the date of posting, the plugin has had a total of 20,578 views, is rated 4.8 out of 5 stars.

What the plugin does is enable, with the simple tick of a box, for a link to be created that you can easily share to allow the public to preview the unpublished post freely.  With the link, no one needs to log into WordPress or do anything else.  It is that simple.

The plugin works by using NONCE.  You may be asking "What is a Nonce?".  Well, it stands for "Number used once" and allows specific URL's be tied to a specific request.  In this case, it allows the post preview to be generated.  You can read more about NONCE on the WordPress.org website here.

Installing the Plugin

public-post-preview Just install the plugin via the administration interface, as you would with any other plugin.  You can either upload the plugin you downloaded via the WordPress Repository or simple search for "Public Post Preview" and it will show as the top entry ready for you to click "install".

Once installed, there is nothing further to do.  To create the shareable public preview URL, simply click the "Enable public preview" button in the right sidebar under the Publish section.

You can then copy and share the link that shows under the "Enable public preview" tick option.  If you decide you no longer wish for the public preview to be accessible, you can just deselect it.

You should be aware that the link will only be valid for 48 hours.  If you need the public preview to extend beyond this period, you will need to recopy the URL, which will automatically update itself although there are a couple of ways you can change the expiry date.

How to Change the Default 48-hour Expiry Date for Shareable Links

There are two ways of doing this:

1.  Custom changes to the functions.php file

The following snippet of code will extend the NONCE time, which in the example below sets it for five days.  You can replace "5" with the required number of days.

add_filter ('ppp_nonce_life', 'my_nonce_life' );
function my_nonce_life() {
return 60 * 60 * 24 * 5; // 5 days
}

2. Public Post Preview Configurator Plugin

Someone took away all the hard work and incorporated the code into a plugin with a simple interface that allows you to choose the number of hours you wish to the Public Post Preview link to be active.  Simply install this plugin as you would any other plugin, and configure it by going to "SETTINGS -> Public Post Preview Configurator".  A screenshot of the configuration screen is below:

public post preview configurator

As you can see, it makes everything extremely simple.

Watch our Video Tutorial

Final Thoughts

This is a plugin that we have used on many occasions to get feedback from third companies on reviews or other tutorials.  It makes the process extremely simple, without having to create cumbersome instructions to enable people to log into your WordPress administration area just to preview one post.  However, there are some potentially interesting uses for this functionality, such as early access to special members or a page with special offers that are only intended to be active for a short time.  While we haven't used it for anything like that, the use case is there.

Related tags
Check out our top user-rated host: SiteGround
Need help choosing a hosting provider?
Check out our top user-rated host: SiteGround