DEV Community

Cover image for Add "Edit in New Tab" link on Posts/Pages
Liton Arefin
Liton Arefin

Posted on

Add "Edit in New Tab" link on Posts/Pages

How to Implement "Edit in New Tab" Links

While editing a post or page you need to click "Edit" link on WordPress. For my use cases, I don't want to leave the main dashboard. Always, I use 'ctrl' button for opening posts to new tab.

By using this feature judiciously, you can significantly improve your writing or editing experience.

Implementing "Edit in New Tab" links in your WordPress posts and pages is a straightforward process with the below codes:

Implement codes as per your needs on 'functions.php' file.

For Posts
Post Editing Code

Code Snippet:

add_filter( 'post_row_actions', 'myposts_tab_row_actions', 10, 2 );
function myposts_tab_row_actions( $actions, $post ) {
    if( get_post_type() === 'post' ) {
        $edit_tag = "<a target='_blank' href='";
        $link = admin_url( 'post.php' );
        $edit_tag .= add_query_arg(array('post' => $post->ID, 'action' => 'edit'), $link);
        $edit_tag .= "'>Edit in New Tab</a>";
        $actions['edit_new_tab'] = $edit_tag;
    }
    return $actions;
}
Enter fullscreen mode Exit fullscreen mode

For Pages

Page Editing Code

Code Snippet:

add_filter( 'page_row_actions', 'mypages_tab_row_actions', 10, 2 );
function mypages_tab_row_actions( $actions, $post ) {
    if( get_post_type() === 'page' ) {
        $edit_tag = "<a target='_blank' href='";
        $link = admin_url( 'post.php' );
        $edit_tag .= add_query_arg(array('post' => $post->ID, 'action' => 'edit'), $link);
        $edit_tag .= "'>Edit in New Tab</a>";
        $actions['edit_new_tab'] = $edit_tag;
    }    
    return $actions;
}
Enter fullscreen mode Exit fullscreen mode

For Custom Post Types

Custom Post Types Editing new tab

Code Snippet:

add_filter( '{custom_post_type_name}_row_actions', 'my_custom_post_type_name_s_tab_row_actions', 10, 2 );
function my_custom_post_type_name_s_tab_row_actions( $actions, $post ) {
    if( get_post_type() === '{custom_post_type_name}' ) {
        $edit_tag = "<a target='_blank' href='";
        $link = admin_url( 'post.php' );
        $edit_tag .= add_query_arg(array('post' => $post->ID, 'action' => 'edit'), $link);
        $edit_tag .= "'>Edit in New Tab</a>";
        $actions['edit_new_tab'] = $edit_tag;
    }    
    return $actions;
}
Enter fullscreen mode Exit fullscreen mode

This is how it looks like:

Open in New tab for Pages

Top comments (0)