As @Sally CJ mentioned, you should set a result of str_replace()
to a variable.
For a content you chose a right filter – the_content
, for tinymce editor you need to use the_editor
filter.
As they a similar, you can use one function for both filters.
In my example I use only one str_replace for opening and closing tags.
Basically, it will be enough, unless you have ‘b>’ text in your content to.
function change_b_to_strong($content){
$content = str_replace('b>', 'strong>', $content);
return $content;
}
add_filter( 'the_content', 'change_b_to_strong' );
add_filter( 'the_editor', 'change_b_to_strong' );
Update
If you output content using get_the_content
for example, this filter will never fire.
You can apply the_content
filter to your text also.
$content = get_the_content();
$content = apply_filters('the_content', $content);