How to reload a post page editor after published?

I have a unique website type that only requires 10-20 seconds to make a new post. I want my WordPress site to reload the editor page automatically after a new post has been published hence I don't need to click "Add New" button in order to load blank post editor page.

Topic posts Wordpress

Category Web


I think that using the redirect_post_location (see codex) hook would be a better way - it fires only in this particular context (when post gets redirected after being edited - see code).

add_filter('redirect_post_location', 'redirect_after_post_update', 10, 2 );
function redirect_after_post_update( $location, $post_id ) {

    // make sure we're in dashboard
    if ( ! is_admin() ) {
        return $location;
    }

    // check if post was published, not updated
    if ( ! isset( $_POST[ 'publish' ] ) ) {
        return $location;
    }

    $new_post_sceen = get_admin_url( '', 'post-new.php');

    if ( ! empty( $new_post_sceen ) ) {
        return $new_post_sceen;
    }

    return $location;
}

In no way I recommend to do that, as it will decrease the flexibility. However, if you have very rarest occasion and really need what you say, then put this code in functions.php:

add_action( 'save_post', 'newpost_redirect', 99);
function newpost_redirect() {
    if ( isset($_POST['original_publish']) && "Publish"==$_POST['original_publish']){ 
        wp_redirect(admin_url('post-new.php') , 302 ); exit;
    }
}

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.