Latest Tweets Widget
[resolved] Any way to 'nofollow' links in tweets? (5 posts)

  1. aerodesigns
    Posted 1 year ago #

    Thanks for the great plugin!

    I was just wondering if there was any way to enter a 'rel="nofollow"' into links contained within tweets either by editing the main plugin file, or with a filter in functions.php?

    Many thanks!


  2. timwhitlock
    Plugin Author

    Posted 1 year ago #

    There are some filters available, see the Other Notes tab

    I think you'll have to render the whole tweet yourself using latest_tweets_render_text, or do some string manipulation on the rendered html afterwards with latest_tweets_render_tweet

  3. aerodesigns
    Posted 1 year ago #

    Thanks Tim, here's a simple replacement for anyone also searching that adds rel=nofollow after using the 'latest_tweets_render_text' filter:

    $tweet = latest_tweets_render_html('twitusername', 1);
    $newtweet = preg_replace("/href/", 'rel="nofollow" href', $tweet);

    Obviously this doesn't check whether a rel=nofollow already exists, however I presume when the tweet is delivered from Twitter it isn't nofollowed anyway.

  4. Abhik
    Posted 1 year ago #

    Can you please share the whole code to make the links in there nofollow?

    Tried different approaches, but failed.

  5. Abhik
    Posted 1 year ago #

    Nevermind, got it working:

    function nofollow_tweets($tweet) {
    	return preg_replace("/href/", 'rel="nofollow" href', $tweet);
    add_filter('latest_tweets_render_tweet', 'nofollow_tweets', 10, 1);

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic