admin管理员组文章数量:1022695
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...
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...
本文标签: customizationWhere in code to replace content before display of page
版权声明:本文标题:customization - Where in code to replace content before display of page? 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745477877a2152404.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论