WordPress.org

Ready to get started?Download WordPress

Forums

Twitter Widget Pro
[resolved] Make image/avatar show up? (6 posts)

  1. privatejoker86
    Member
    Posted 1 year ago #

    I'm using to this to produce a feed by username. I was hoping that I would be able to show the image/avatar associated with the tweet (such as original image in the case of a retweet).

    If this is not a feature that I'm missing, are you able to perhaps provide some vague direction? I believe I could take it from there.

    Thank you very much for reading and taking the time to respond.

    http://wordpress.org/extend/plugins/twitter-widget-pro/

  2. Aaron D. Campbell
    Member
    Plugin Author

    Posted 1 year ago #

    You could use the "widget_twitter_content" filter to modify the tweet text to include the avatar of the person that tweeted it. The actual tweet info from Twitter is supplied as the second argument to that filter, and I think that would have everything you need in it.

  3. privatejoker86
    Member
    Posted 1 year ago #

    Thanks for taking the time to reply. That ended up sending me down the path I used. For anyone trying to do what I did, here's my solution:

    Inside the loop (around line 640):

    foreach ( $tweets as $tweet ) {

    I added:

    if ($tweet->retweeted_status->user->profile_image_url == "") {
    						$widgetContent .= "<span class='entry-image'><img src='".$tweet->user->profile_image_url."' /></span>";
    				} else {
    						$widgetContent .= "<span class='entry-image'><img src='".$tweet->retweeted_status->user->profile_image_url."' /></span>";
    
    				}
  4. Aaron D. Campbell
    Member
    Plugin Author

    Posted 1 year ago #

    The problem with doing it that way is that the next time I release an update to the plugin you'll have to edit it again (and then again and again as the plugin continues to receive updates). Instead try this:

    function range_widget_twitter_content( $content, $tweet ) {
    	$image_link = '<a href="http://twitter.com/%1$s"><span class="entry-image"><img src="%2$s" /></span></a>%3$s';
    	if ( empty( $tweet->retweeted_status ) )
    		$content = sprintf( $image_link, $tweet->user->screen_name, $tweet->user->profile_image_url, $content );
    	else
    		$content = sprintf( $image_link, $tweet->retweeted_status->user->screen_name, $tweet->retweeted_status->user->profile_image_url, $tweet->retweeted_status->text );
    
    	return $content;
    }
    add_filter( 'widget_twitter_content', 'range_widget_twitter_content', null, 2 );

    That will add the profile image to each tweet, link that profile image to the correct user account on Twitter, and also replace the content with the original tweet content if it's a retweet.

  5. Aaron D. Campbell
    Member
    Plugin Author

    Posted 1 year ago #

    Oh, that code should go in another plugin or in your theme's functions.php file.

  6. privatejoker86
    Member
    Posted 1 year ago #

    Thank you so much for both the great plug-in and the time to help. This is working great in my functions.php file.

    I'm still trying to figure out how all these filters add content without clobbering each other, but that's just my newness to WP's plug in framework I think.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic