0

I wish to make a replacement in all pages of a WordPress installation, after the page content has been read from the database and before it is displayed on visitor screen (of course).

Where in the code do I insert the following statement that will make the replacement?

$page = str_replace($target, $replace, $page);

I run an updated WordPress using 2016 child theme. Among others I have a dedicated single.php and a functions.php

Thank you

2

1 Answer 1

2

If you use native editor (and not some PageBuilder that stores data in its way), then you should be able to use the_content filter to do that:

add_filter( 'the_content', 'my_the_content_filter' );
function my_the_content_filter( $content ) {

    $content = str_replace(...);

    return $content;
}

You might put some conditions in there, to check if you modify only pages or only on single page and so on...

1
  • Thanks, I appreciate. It worked straight out of the box.
    – KaE
    Commented May 22, 2019 at 12:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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