Here 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 :
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.