Redirect user to new post when published using wp_redirect

Adding this snippet to the functions.php of your wordpress theme will redirect a user to the new post or page after it is published.

 

 

add_filter('redirect_post_location', 'redirect_to_post_on_publish_or_save');
function redirect_to_post_on_publish_or_save($location){
if (isset($_POST['save']) || isset($_POST['publish'])) {
if (preg_match("/post=([0-9]*)/", $location, $match)) {
$pl = get_permalink($match[1]);
if ($pl) {
wp_redirect($pl);
}
}
}
}

Be Sociable, Share!

Leave a comment