Remove “Private” + “:” in title does not work

I would like to remove the “private” prefix for each post title.
I found the filter here.
I managed to removed the word “Private” but when I concatenate with ” : “.
That does not work anymore.
I checked $title value before the str_replace and it´s already translated with ” : “.

Class FrontEnd{

    protected function front_end_init() {
        add_filter( 'the_title', array( $this, 'remove_private_prefix' ) );
    }

    public static function remove_private_prefix( $title ) {
        $title = str_replace( __( 'Private' ) . " : ", '', $title);
        return $title;
    }
}

How can I fix this ?

4 Answers
4

The simplest answer is as follows:

add_filter( 'private_title_format', function ( $format ) {
    return '%s';
} );

It uses the private_title_format to change the format of the title to just the post title, without any unnecessary classes or functions.

Leave a Comment