“Maximum function nesting level of ‘100’ reached” after adding a new filter

the_title() calls your function again. If you want to avoid that, remove the callback inside of your function:

function filter_title_after() {
    remove_filter( current_filter(), __FUNCTION__ );
    // the rest of your code.

But you shouldn’t call the_title() in your function at all: it prints the title – this is not what you want – and you get the original title and ID already as an argument from WordPress. Use it.

Also, testing for POST requests should be done by checking $_SERVER[ 'REQUEST_METHOD' ].

function filter_title_after( $title, $post_id ) {

    if ( ! is_singular() )
        return $title;

    if ( 58 !== (int) $post_id )
        return $title;

    if ( 'POST' !== $_SERVER[ 'REQUEST_METHOD' ] )
        return $title;

    return "Congratulation";
}

add_filter( 'the_title', 'filter_title_after', 10, 2 ); 

Leave a Comment