redirect_post_location
Filters the final URL to which WordPress redirects the user when a post is saved, published, or updated.
For example, when creating a post the URL is /wp-admin/post-new.php. After clicking “Save” or “Publish”, it becomes wp-admin/post.php?post=3061&action=edit&message=10. This new URL can be changed with the redirect_post_location filter.
Usage
function filter_function_name_11( $location, $post_id ) {
// Filter...
return $location;
}
add_filter( 'redirect_post_location', 'filter_function_name_11', 10, 2 );
Parameters
- $location(string)
- The URL to which the user will be redirected.
- $post_id(integer)
- The ID of the post currently being processed.
Examples
#1 Redirect to the post list when creating a post
Suppose that after creating or updating a post, the user must be redirected to the admin page containing all posts instead of returning to the same post editing page. Use the redirect_post_location filter and admin_url():
add_filter( 'redirect_post_location', 'redirect_to_list_after_publish_post' );
/**
* Redirect to edit.php when saving or publishing a post.
*/
function redirect_to_list_after_publish_post( $location ) {
if ( isset( $_POST['save'] ) || isset( $_POST['publish'] ) )
return admin_url( "edit.php" ); // The link will be: http://example.com/wp-admin/edit.php
return $location;
}Changelog
| Since 2.9.0 | Introduced. |
Where the hook is called
redirect_post_location
wp-admin/includes/post.php 2228
wp_redirect( apply_filters( 'redirect_post_location', $location, $post_id ) );