Wordpress Previwe

Change preview post link in wordpress admin

post linkHere we are discussing a scenario where we have the requirement to change the URL of preview button which is showing at the right section under publish block for a particular post. Generally we do not want to modify this URL because it is better to use wordpress default preview functionality in spite of using our custom one.

Look at the image in this post, it will guide you about the link which we are trying to modify.

In some cases we do not want to proceed with the wordpress default preview, we want our custom preview page. So, for this just code for the preview page by using the post id and save it where ever you want. To make this happen, we are using a default wordpress filter that is “preview_post_link”.
This will filter the URL used for a post preview. The same filter will also work for pages, if you want to change the URL for wordpress preview button on pages then this same filter will do this for you.

Please do not use “preview_page_link” filter, this hook is no more in wordpress now, it is deprecated from the wordpress latest versions.
So, just paste the below mentioned code to your functions.php file of your current theme :

function wptricks24_post_preview_link($preview_link, $post) {
   if ( get_post_status ( $post->ID ) != 'draft' && get_post_status ( $post->ID ) != 'auto-draft' ) {
         //preview URL for all published posts
         return home_url()."?preview_id=".$post->ID; //put your new URL here
    } else {
       //preview URL for all posts which are in draft
        return home_url()."?custom_preview=".$post->ID; //put your new URL here
add_filter( 'preview_post_link', 'wptricks24_post_preview_link', 10, 2 );

Here we are done with the change in link for preview button. We can create separate preview pages for posts for every status which exists, just need to apply the conditions to the above code as per your choice.
In the same manner we can change the URL of the preview button for pages in wordpress admin.

Mostakim Hossen

I am Mostakim Hossain, a Web designer and developer, 23 years of age. I have been working as a freelance (upwork) for almost 2 years now and I will be glad in helping you create your next awesome project.

I have created lots of public and private websites(some shown below) and always looking for more work to learn from. I am using PHP as my primary programming language. You can see my skill set beside this text.

I am a person who is willing to learn and adapts quickly. I am keen to design and security. I believe in the core principles of Open Source and support it. I have a minimalist approach to design and usability. Simplicity is beauty they say.
Masters of Accountancy : Asian University of Bangladesh
I’m here to answer any questions you might have about our products and services. Feel free to contact me using any of the following methods:

Email : support@smarterdevs.com

Leave a Reply

Your email address will not be published. Required fields are marked *


Coupon : happynewyear

60% OFF

Stay updated with all latest updates,upcoming plugins & much more.
WordPress Themes