Tuning Twitter embeds in WordPress: nofollow links and centered embed

Since last year WordPress team added auto-embed support for Twitter status updates, leading to some kind of design and SEO problems. Let's try to solve both.

As you may know, in recent WordPress versions placing a Twitter URL like

https://twitter.com/SochiProblems/status/430809254941843457

inline your post or page text turned it into this widgetized (and more appealing) tweet display
https://twitter.com/SochiProblems/status/430809254941843457
By default Twitter embeds are left aligned and cannot be centered with paragraph formatting toolbar.

Even more, in a Google centric world this leads to any kind of junk URLs (hashtags, @usernames, pics) being injected with old era internet links (aKa Non-Non Followed).

Short review of public Big G position about widgets: nofollow it

Solution Provided:

Include in the functions.php file in your theme directory to have a css centered, URL clean tweet embedded widget

/* Keep URL for updates */
/* https://imojito.com/twitter-embed-nofollow-centered-wordpress.html */ 
add_filter('oembed_result','twitter_mod',10,3);
function twitter_mod($html, $url, $args) {
if (false !== strpos($url, 'twitter.com')) {
/* Center Widget */
$html = str_replace('class="twitter-tweet"','class="twitter-tweet tw-align-center"',$html);
/* NoFollow Links */
$html = str_replace('<a','<a rel="nofollow"',$html);
}
return $html;
}

A partial solution, given the fact that Google may load the twitter widget javascript and self-display the colorful and old style linked Tweet

Did you enjoy this post and find it valuable?

📡 Subscribe and sign the 📜 Guestbook!

Tip the author! Don't know what Bitcoin is yet?

1Mojitovwnpokdo8uLXvG93pEhBF6MNFoo

Tagged as: , ,