custom post types – Change CPT Edit Target for Admin List
hoping you can help with this conundrum of mine.
I have created a CPT, and am changing the link in the admin list pages for it to be the front-end permalink. What I’d like to do now is change the target to _blank
, so it pops open in a new tab.
However, the edit_post_link
filter does not appear to be working.
Here is what I currently have:
// swap the link for a #
add_filter( 'get_edit_post_link', function( $_url, $_id, $context ) use( $_pt ) {
// if it's the alerts post type
if( get_post_type( $_id ) == $_pt ) {
// get the frontend permalink to this item
$_link = get_the_permalink( $_id );
// return the front-end link
return $_link;
}
// default to the url
return $_url;
}, 10, 3 );
add_filter( 'edit_post_link', function( $link ) {
var_dump("HERE-----------------------------------------------------------------");
$link = str_replace( '<a ', '<a target="_blank" ', $link );
return $link;
}, PHP_INT_MAX );
I have also tried the filter like this as well:
add_filter( 'edit_post_link', function( $link, $post_id, $text ) {
var_dump("HERE-----------------------------------------------------------------");
$link = str_replace( '<a ', '<a target="_blank" ', $link );
return $link;
}, 10, 3 );
Neither of these do anything, not even the var_dump shows in wp-admin list page for the CPT. Please do note that I am removing the post_row_actions
(well, all except trash) because I am pulling the data for the CPT’s from an API, and I want 0 editting capabilities, and that seemed the most logical route…
Is there another filter that I should be hooking into for this? Or is this something that is truly “broken” in WordPress?
Leave an answer