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) {

Comments  Leave a Reply

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!