0
function replace_text($text) {
$text = str_replace('old-text', 'new-text', $text);
return $text;
}

add_filter('the_content', 'replace_text');

Is there any way to apply this to entire page? I mean not only to content but also to header, footer and sidebar too.

  • 1
    You can use PHP output buffering. Also, there is a WordPress plugin. – Max Yudin Sep 22 '18 at 15:08
  • What's the use case here? – Michael Sep 22 '18 at 16:54
  • Thank you. That plugin solved my problem. The reason is to change image urls from site.com/wp-content/uploads to static.site.com. Cdn plugins change to static.site.com/wp-content/uploads so i can not use them. – ahmet Sep 22 '18 at 19:32
0

The reason is to change image urls from site.com/wp-content/uploads to static.site.com. Cdn plugins change to static.site.com/wp-content/uploads so i can not use them.

I think it's better to update the database content instead of replacing strings in each page-load.

Check this easy DB replacement tool: https://github.com/interconnectit/Search-Replace-DB

Keep in mind to remove it after you've done your changes!

  • Thank you. I knew that but that does not suits my needs. Because when upload new image, WordPress set the link as site.com/wp-content/uploads. So every time I upload new image, I need to update database. It is not useful. – ahmet Sep 24 '18 at 9:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.