如何将文本替换为php中的链接?

I have the following function in my wordpress website, works well with page text......

function replace_text($text) {
    $text = str_replace('Cookbook', 'All Recipes', $text);
    $text = str_replace('look-for-that-string', 'replace-with-that-string', $text);
return $text;
}
add_filter('the_content', 'replace_text');

But what I'm trying to target is text that is generated by a menu plugin,.... I've tried by adding the actual element code (below) in it's entirety but it does not change the menu text. It still say "Cookbook" I can't touch the menu plugin code unfortunately.

 function replace_text($text) {
     $text = str_replace('<span class="145-test 120-test 115-test loaded- 
header">Cookbook</span>', '<span class="145-test 120-test 115-test loaded-header">All Recipes</span>', $text);
$text = str_replace('look-for-that-string', 'replace-with-that-string', $text);
return $text;
 }
 add_filter('the_content', 'replace_text');

Is there something I need so that it switches the text?

does it have to do with the_content?