intempodk
Forum Replies Created
-
Im actually not sure this is the case at the moment, as it starts to go down again, i dont know how page views can go down after registrered, i guess its a google issue.
Forum: Developing with WordPress
In reply to: Change post data before render to screenOkay after fidling some more, it seems the problem now is the preg_replace, it makes it look like this with newline at url (not working)
<!-- wp:embed {"url":"https://twitter.com/thename/76396939461923712","type":"rich","providerNameSlug":"twitter","responsive":true} --> <figure class="wp-block-embed is-type-rich is-provider-twitter wp-block-embed-twitter"><div class="wp-block-embed__wrapper"> https://twitter.com/thename/76396939461923712 </div></figure> <!-- /wp:embed -->
when output must look like this (working)
<!-- wp:embed {"url":"https://twitter.com/thename/76396939461923712","type":"rich","providerNameSlug":"twitter","responsive":true} --> <figure class="wp-block-embed is-type-rich is-provider-twitter wp-block-embed-twitter"><div class="wp-block-embed__wrapper">https://twitter.com/thename/76396939461923712</div></figure> <!-- /wp:embed -->
i tried changing the preg_replace code from this:
$post['post_content'] = preg_replace( '/<blockquote class="twitter-tweet".*?>.*?\) <a href="(.*?)\?.*?">.*?<\/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 -->', $post['post_content'] );
to trim, and to preg_replace new lines, nothing removes the newline…
trim(preg_replace('["\r\n", "\n", "\r"]', ' ', '<figure class="wp-block-embed is-type-rich is-provider-twitter wp-block-embed-twitter"><div class="wp-block-embed__wrapper">${1}</div></figure>'))
It there some sort of character i can use to force it into one single line? something im missing?
Forum: Developing with WordPress
In reply to: Change post data before render to screenfunction twitter_filter_content( $text ) { if ( is_singular() && in_the_loop() && is_main_query() ) { $text = preg_replace( '/<blockquote class="twitter-tweet".*?>.*?\) <a href="(.*?)\?.*?">.*?<\/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); //var_dump( $text ); } return $text; } add_filter( 'the_content', 'twitter_filter_content');
This code DOES change the text correctly in var_dump, but its not working in the outputtet post, it just shows the twitter url, no twitter box, its like it dont use the block, maybe it needs to be run other way, earlier in post data?
Think i read something about post() and apply_filters(), to make shortcodes work but not sure how to use that in a simple plugin like this.
Forum: Developing with WordPress
In reply to: Change post data before render to screenWhat im trying to do is, it actually “edits” the post when a user clicks it.
Like, when you manually open it in wordpress editor and edits it, then saves it.This just does it on the fly before its shown to the user.
But adding a <– ! block in the_content wont work, as wordpress dont process it, it will just show up as “text” in the html source code
Forum: Developing with WordPress
In reply to: Change post data before render to screenI tried that, it just shows
string(7000) ”
a copy of the post
”
and the normal post after.it does not show the post “raw source” i can edit before render (the source you see when you edit the post).
as im trying to force a twitter block in, it needs to be changed before turning into html output