How to return to a post after creating/editing it?

  • Unknown's avatar

    I’d like to have my site set up so that, after a user creates or updates a post, they are returned to the non-editing view of that post. I can’t quite figure out how to do this; I’d assume that add_action and wp_after_insert_post are likely to be involved, but I can’t quite get there.

    Here is what is probably a really bad idea:

        function sf_change_post_destination( $post_id, $post_after, $post_before ) {
        	$the_url = get_home_url() . "/?p=" . $post_id;
        	wp_redirect( $the_url );
        	exit;
        }
        
        add_action( 'wp_after_insert_post', 'sf_change_post_destination' , 10000, 3);    
    

    This *seems to* work; the idea is to use a very high priority value in the add_action() call so that it should be the last action to run. But, of course, the exit call (required for this to “work”) terminates the update process, and who knows what essential things are getting cancelled because of it. So, bad idea. But is there a better one? Any advice? Thanks!

  • Hi there,

    It appears that you’re using the open-source WordPress software and therefore you need to seek help at these forums:

    https://wordpress.org/support/forums/

    These forums are for providing support to WordPress.com hosted sites only. If you want to know more about the differences between WordPress.com and the WordPress software you can read this document:

    WordPress.com vs. WordPress.org

  • The topic ‘How to return to a post after creating/editing it?’ is closed to new replies.