I’ve stripped Private:
and Protected:
from my custom post title that are forced to be private. I’m using CSS Tricks’ snippet for doing so:
function the_title_trim($title) {
if( is_admin() )
return $title;
$title = esc_attr($title);
$findthese = array(
'#Protected:#',
'#Private:#'
);
$replacewith = array(
'', // What to replace "Protected:" with
'' // What to replace "Private:" with
);
global $post;
if( 'mycpt' === get_post_type($post) ) {
$title = preg_replace( $findthese, $replacewith, $title );
}
return $title;
}
add_filter('the_title', 'the_title_trim');
It works fine as expected.
But recently when I switched to a different language, I found it’s not working. And you can guess easily that, the $findthese
array is failing to match any other language’s strings for those specified.
How can I use preg_replace()
for stripping the texts, that supports i18n strings?