On this page
get_preview_post_link( int|WP_Post $post = null, array $query_args = array(), string $preview_link = '' ): string|null
Retrieves the URL used for the post preview.
Description
Allows additional query args to be appended.
Parameters
$postint|WP_Post Optional-
Post ID or
WP_Postobject. Defaults to global$post.Default:
null $query_argsarray Optional-
Array of additional query args to be appended to the link.
Default:
array() $preview_linkstring Optional-
Base preview link to be used if it should differ from the post permalink.
Default:
''
Return
string|null URL used for the post preview, or null if the post does not exist.
Source
File: wp-includes/link-template.php. View all references
function get_preview_post_link( $post = null, $query_args = array(), $preview_link = '' ) {
$post = get_post( $post );
if ( ! $post ) {
return;
}
$post_type_object = get_post_type_object( $post->post_type );
if ( is_post_type_viewable( $post_type_object ) ) {
if ( ! $preview_link ) {
$preview_link = set_url_scheme( get_permalink( $post ) );
}
$query_args['preview'] = 'true';
$preview_link = add_query_arg( $query_args, $preview_link );
}
/**
* Filters the URL used for a post preview.
*
* @since 2.0.5
* @since 4.0.0 Added the `$post` parameter.
*
* @param string $preview_link URL used for the post preview.
* @param WP_Post $post Post object.
*/
return apply_filters( 'preview_post_link', $preview_link, $post );
}
Hooks
- apply_filters( 'preview_post_link',
string $preview_link ,WP_Post $post ) -
Filters the URL used for a post preview.
Related
Uses
| Uses | Description |
|---|---|
| is_post_type_viewable() wp-includes/post.php | Determines whether a post type is considered “viewable”. |
| set_url_scheme() wp-includes/link-template.php | Sets the scheme for a URL. |
| add_query_arg() wp-includes/functions.php | Retrieves a modified URL query string. |
| get_permalink() wp-includes/link-template.php | Retrieves the full permalink for the current post or post ID. |
| apply_filters() wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. |
| get_post() wp-includes/post.php | Retrieves post data given a post ID or post object. |
| get_post_type_object() wp-includes/post.php | Retrieves a post type object by name. |
Used By
| Used By | Description |
|---|---|
| WP_REST_Autosaves_Controller::prepare_item_for_response() wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php | Prepares the revision for the REST response. |
| WP_Posts_List_Table::handle_row_actions() wp-admin/includes/class-wp-posts-list-table.php | Generates and displays row action links. |
| get_sample_permalink_html() wp-admin/includes/post.php | Returns the HTML of the sample permalink slug editor. |
| _admin_notice_post_locked() wp-admin/includes/post.php | Outputs the HTML for the notice to say that someone else is editing or has taken over editing of this post. |
| post_preview() wp-admin/includes/post.php | Saves a draft or manually autosaves for the purpose of showing a post preview. |
| wp_ajax_get_permalink() wp-admin/includes/ajax-actions.php | Ajax handler to retrieve a permalink. |
| post_submit_meta_box() wp-admin/includes/meta-boxes.php | Displays post submit form fields. |
| wp_admin_bar_edit_menu() wp-includes/admin-bar.php | Provides an edit link for posts and terms. |
| _wp_link_page() wp-includes/post-template.php | Helper function for wp_link_pages() . |
Changelog
| Version | Description |
|---|---|
| 4.4.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/get_preview_post_link