get_edit_post_link
Allows you to change the post edit link.
Usage
add_filter( 'get_edit_post_link', 'wp_kama_get_edit_post_link_filter', 10, 3 );
/**
* Function for `get_edit_post_link` filter-hook.
*
* @param string $link The edit link.
* @param int $post_id Post ID.
* @param string $context The link context. If set to 'display' then ampersands are encoded.
*
* @return string
*/
function wp_kama_get_edit_post_link_filter( $link, $post_id, $context ){
// filter...
return $link;
}
- $link(string)
- The post edit link.
- $post_id(int)
- The post ID.
- $context(string)
- The context in which the link is requested. If
displayis specified, ampersands will be encoded.
Examples
#1 Change the post edit link
Suppose the front end has a form for adding and editing the “Tow Truck” post type. By default, such posts can also be edited in the admin area. To keep all the logic in one place, replace admin edit links with links that lead to the front end:
add_filter( 'get_edit_post_link', 'change_post_edit_url', 11, 2 );
function change_post_edit_url( $link, $post_id ) {
if ( get_post_type( $post_id ) === 'evacuator' ) {
return home_url( '/evacuator-adv/?eap=' . $post_id );
}
return $link;
}

Changelog
| Since 2.3.0 | Introduced. |
Where the hook is called
get_edit_post_link
wp-includes/link-template.php 1498
return apply_filters( 'get_edit_post_link', $link, $post->ID, $context );
Where the hook is used in WordPress
wp-includes/class-wp-customize-manager.php 1950
add_filter( 'get_edit_post_link', '__return_empty_string' );