To change the URL of the "Preview post" button in WordPress, you can use the preview_post_link
filter. This filter allows you to modify the URL of the preview link that is displayed when editing a post or page.
Here is an example of how to use the preview_post_link
filter to change the URL of the "Preview post" button:
add_filter('preview_post_link', 'custom_preview_post_link'); function custom_preview_post_link($url) { $post_id = get_the_ID(); $url = add_query_arg(array( 'preview' => 'true', 'post_id' => $post_id ), 'http://www.example.com/preview'); return $url; }
This code registers a custom function that uses the add_query_arg
function to add query parameters to the preview URL. The preview
parameter is set to true
to indicate that the link is a preview link, and the post_id
parameter is set to the ID of the post or page being edited.
It's important to note that this is just one example of how to use the preview_post_link
filter to modify the preview link URL. You can use this filter to customize the preview link URL in any way that you like, depending on your specific requirements. Consult the WordPress documentation and online resources for more information.