Use the redirect_post_location
filter and admin_url()
function.
add_filter( 'redirect_post_location', 'wpse_124132_redirect_post_location' );
/**
* Redirect to the edit.php on post save or publish.
*/
function wpse_124132_redirect_post_location( $location ) {
if ( isset( $_POST['save'] ) || isset( $_POST['publish'] ) )
return admin_url( "edit.php" );
return $location;
}
To redirect to a different url, add everything after the /wp-admin/
portion of the url. I used "edit.php"
because the intended url was: http://example.com/wordpress/wp-admin/edit.php
.
The redirect_post_location
filter is not documented in the Codex Filter Reference. You can find it in the \wp-admin\post.php
file near line 73. This is the WordPress code in the trunk version of WordPress:
wp_redirect( apply_filters( 'redirect_post_location', $location, $post_id ) );
As you can see, you can also test the $post_id
redirect based on the $post_id
or any information obtained from it. To use this second parameter of the filter, you need to pass the priority and _accepted_args_ parameters in the filter call:
add_filter( 'redirect_post_location', 'wpse_124132_redirect_post_location', 10, 2 );
And update the function parameters:
/**
* Redirect to the edit.php on post save or publish.
*/
function wpse_124132_redirect_post_location( $location, $post_id ) {
if ( isset( $_POST['save'] ) || isset( $_POST['publish'] ) ) {
// Maybe test $post_id to find some criteria.
return admin_url( "edit.php" );
}
return $location;
}