Skip to content

Instantly share code, notes, and snippets.

@wpmark
Created October 8, 2014 09:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wpmark/62ca0ca2638e7da56e9a to your computer and use it in GitHub Desktop.
Save wpmark/62ca0ca2638e7da56e9a to your computer and use it in GitHub Desktop.
Latest Tweets Widget - Add Follow Button
/***************************************************************
* Function seis_tweets_follow_buttons()
* Adds follow buttons using images from theme image folder with
* names based on the twitter handle given in the widget.
***************************************************************/
function seis_tweets_follow_buttons( $items, $screen_name ) {
/* make the screen name lower case */
$screen_name = strtolower( $screen_name );
/* build the link to follow */
$follow_url = 'http://twitter.com/' . $screen_name;
/* get the image url from theme images based on screen name */
$img_url = get_stylesheet_directory_uri() . '/images/follow-button-' . $screen_name . '.png';
/* generate button with link */
$button = '<div class="follow"><a class="follow-link" href="' . esc_url( $follow_url ) . '"><img src="' . esc_url( $img_url ) . '" alt="Follow ' . $screen_name . ' on Twitter" class="follow-img" /></a></div>';
$new_items = '';
/* loop through the items list */
foreach( $items as $item ) {
/* add item string to new items */
$new_items .= '<div class="tweet-wrap">' . $item . '</div>';
}
/* add button to end of items */
$new_items = $new_items . $button;
return $new_items;
}
add_filter('latest_tweets_render_list', 'seis_tweets_follow_buttons', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment