The preview_post_link
filter in WordPress can be used to change the URL of the Preview Post button on the post editor screen. You can use the following code to change the URL of the Preview Post button:
function custom_preview_post_link( $preview_link, $post ) {
$preview_link = home_url( '/my-custom-preview-url/?p=' . $post->ID );
return $preview_link;
}
add_filter( 'preview_post_link', 'custom_preview_post_link', 10, 2 );
This code adds a filter function that modifies the URL of the Preview Post button. The function takes two parameters: $preview_link
and $post
. The $preview_link
parameter contains the default URL of the Preview Post button, and the $post
parameter contains the post object being previewed.
In this example, the filter function changes the URL of the Preview Post button to home_url('/my-custom-preview-url/?p=' . $post->ID)
, where home_url
returns the home URL of the WordPress site, and $post->ID
returns the ID of the post being previewed.
Place this code in your theme’s functions.php
file or in a custom plugin to change the URL of the Preview Post button.