Change post data before render to screen
-
Hi all,
Im trying to edit some post content globally on all posts, that changes some text using regex to display twitter post from other data.
I tried ALOT of ways to do this, but nothing worked.
Wrote a small plugin for this, just simple one with this code:
function twitter_filter_content( $text ) { if ( is_singular() && in_the_loop() && is_main_query() ) { $text = preg_replace('/<blockquote class="twitter-tweet".*<a href="(.*)">.*<\/a><\/blockquote>/s', '<!-- wp:embed {"url":"${1}","type":"rich","providerNameSlug":"twitter","responsive":true,"className":""} --><figure class="wp-block-embed is-type-rich is-provider-twitter wp-block-embed-twitter"><div class="wp-block-embed__wrapper">${1}</div></figure><!-- /wp:embed -->', $text); } return $text; } add_filter( 'the_content', 'twitter_filter_content', 1);
This preg_replace code should work and been tested at regex101.com and online-free-tools.com/en/php_preg_replace_test_pattern and should be working, atleast there, but its not working on the site, my guess is, its looking at the html output code after render and that will never work.
It need to change the post source text BEFORE wordpress changes to html post.
Anyone knows a trick? ??
Thanks.
Viewing 7 replies - 1 through 7 (of 7 total)
Viewing 7 replies - 1 through 7 (of 7 total)
- The topic ‘Change post data before render to screen’ is closed to new replies.