Deregister Custom the_title Filter for edit_post_link


Can’t figure out how to leave edit_post_link untouched with a custom the_title filter so that only the title gets the filter applied. This is within a plugin that could apply to any theme, some of which use ‘the_title()’ as part of the text/link for ‘edit_post_link()’.

The context usage is per post within the main loop of search results.

Here’s a simplified version of the custom filter to I’m using:

add_filter( 'the_title', 'codejp3_mss_results_title_filter', 10, 2 );
function codejp3_mss_results_title_filter( $title, $post_id = null ) {
    global $wp_query;
    if( ! is_admin() && ! is_network_admin() && $wp_query->is_main_query() && $wp_query->is_search && in_the_loop() ){
        // code to alter the title here
        return $title;

This works great for preventing changes to ‘the_title’ in widgets/menus/etc like a lot of people seem to have. BUT, it’s still applying the title alterations to ‘edit_post_link()’.

I’ve tried adding the following conditions to my ‘if’ statement without success:

! doing_action('edit_post_link')
! doing_filter('edit_post_link')

I’ve tried hooking into the ‘edit_post_link’ filter and deregistering my custom ‘the_title’ filter, but my custom title filter has already been applied to the ‘edit_post_link’ so deregistering it does no good:

add_filter( 'edit_post_link', 'deregister_title_filter', 9, 3 );
function deregister_title_filter($link, $post_id, $text) {
    remove_filter( 'the_title', 'codejp3_mss_results_title_filter' );
    return $link;

Note the priority difference of 9 and 10, which is yet another method I’ve tried, without success.

How can I prevent my custom ‘the_title’ filter from being applied to ‘edit_post_link’ when a particular theme uses ‘the_title’ as part of the edit post link/text?

John Patrick Hayden 1 year 2022-11-15T21:49:05-05:00 0 Answers 0 views 0

Leave an answer