最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

customization - Where in code to replace content before display of page?

programmeradmin2浏览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

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
Add a comment  | 

1 Answer 1

Reset to default 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...

发布评论

评论列表(0)

  1. 暂无评论