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.
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;
}
For Pages
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;
}
For Custom Post Types
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;
}
This is how it looks like:
Top comments (0)