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
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
Share Improve this question asked May 21, 2019 at 4:55 KaEKaE 33 bronze badges 2- Possible duplicate of Is it possible to change the contents of "the_content()"? – norman.lol Commented May 21, 2019 at 7:18
- The solutions are similar in both questions. But the questions are somewhat differently put. Maybe both questions should be kept, for easy reference? – KaE Commented May 21, 2019 at 8:58
1 Answer
Reset to default 2If 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...
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745477879a4629428.html
评论列表(0条)