Redirect posts to post editor page based on query string

Implementation notes:

  1. You need to use that function with an appropriate action hook. For example, template_redirect hook can be used here.

  2. If you want URL to have ?edit, then empty check is not necessary, if you want URL to have something like ?edit=1, then use ! empty check.

  3. Check and ignore if we are already on the admin pages.

  4. Check and proceed if we are on a single post page.

CODE:

Following is an example code that’ll work:

function fyz_edit_redirect() {
    if( ! is_admin() // skip if we are on admin pages already
            && is_single() // apply only if it's a single post
            && isset( $_GET['edit'] ) && ! empty( $_GET['edit'] ) ) {
        wp_safe_redirect( admin_url( '/post.php?action=edit&post=" . get_the_ID() ) );
        exit;
    }
}

add_action( "template_redirect', 'fyz_edit_redirect' );