Skip to content
  • Home
  • Shortcodes
  • Plugins
  • IT / Windows
  • Programming & Development
  • Random

3

Add Twitter Follow Button to WordPress 3.0 with a simple shortcode

You can call this lump of postings my WordPress Social shortcode series. Here is the current lineup from this post; Google +1 and Facebook Like and Send, Twitter Share button. You have come here for the Twitter Follow code and here you go. Guessing you will probably only have one of these the code is best suited for displaying one shortcode per page.

The code was built with Twitter Follow API documentation. To understand all the capabilities this shortcode supports you may what to head over and check out the types.

1) Open your Functions.php file – Create if does not exist in root of template

Assuming you have more than average knowledge and the ability to edit theme files directly in WordPress. This file serves as an entry point for your custom code in WordPress 3.0. So if you have custom classes or external code you need to run within the WordPress context you will add the hooks and init() code blocks there. The file location is ( site/wp-content/themes/YOUR-Theme/functions.php ).

2) Add the Twitter Follow Shortcode to WordPress

Double-click the code box below and copy / paste in the functions.php file.

function twitter_follow($atts, $content=null){
/* Author: Nicholas P. Iler
 * URL: http://www.ilertech.com
 */
	extract(shortcode_atts(array(
		'show_count' => false,
		'button' => 'blue', // blue, grey
		'text_color' => '',
		'link_color' => '',
		'lang' => '', // en, fr, de, it, es, ko, ja | ref: http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
		'width' => '',
		'align' => ''
		), $atts));
		$twitter_follow_code = <<<HTML
	<a href="http://twitter.com/$content" class="twitter-follow-button"
		data-show-count="$show_count"
		data-button="$button"
		data-text-color="$text_color"
		data-link-color="$link_color"
		data-lang="$lang"
		data-width="$width"
		data-align="$align">Follow @$content</a>
<script src="http://platform.twitter.com/widgets.js" type="text/javascript"></script>
HTML;
		return $twitter_follow_code;
}
add_shortcode('tf', 'twitter_follow');

3) Add to Template Page with Shortcode

This is the most versatile way of adding the final piece of code. The shortcode.
Fastest – Use for Single Pages

<!-- Twitter Follow Shortcode -->
<?php echo do_shortcode("[tf]Nickiler[/tf]"); ?>

Usage Examples
No Count:
Follow @Nickiler

[tf]Nickiler[/tf]

Show Count:
Follow @Nickiler

[tf show_count=true]Nickiler[/tf]

Show with Grey Button
Follow @Nickiler

[tf show_count=true button='grey']Nickiler[/tf]

Related Posts

  • Add Twitter Share Button to WordPress 3.0 with a simple shortcode
  • Add Facebook Like Button to WordPress 3.0 with a simple shortcode
  • Add Google + 1 to WordPress 3.0 with a simple shortcode
  • Escape WordPress shortcodes in content with a shortcode
  • The slug “?” is already in use by another term

About Nickiler

Web Developer and Systems Admin
View all posts by Nickiler →

Follow @Nickiler
Posted on July 4, 2011 by Nickiler
This entry was posted in Shortcodes and tagged shortcode, twitter, twitter follow, wp. Bookmark the permalink.

3 Responses to Add Twitter Follow Button to WordPress 3.0 with a simple shortcode

  1. Mircea says:
    August 6, 2011 at 12:09 AM

    Hello. Can I somehow to call on your services for a fee to bring some changes to my wordpress site? Thanks in advance! All the best.

    Reply
  2. Nic says:
    November 27, 2011 at 4:28 PM

    Thanks for the great tutorials. I’m having trouble getting multiple shortcodes to show up on the same line. The html in the php seems pretty trivial, but somehow they still print on separate lines. Do you have any suggestions on how to fix this? — http://www.onthemoveproductions.com/?page_id=38

    Reply
    • Nicholas P. Iler says:
      November 28, 2011 at 12:31 AM

      Hey Nic, Funny thing is the CSS work turned out to be much more painful than putting the shortcodes together. Facebook has some in-line styles that conflict with others I found. What I did for this site was display other short codes before the Facebook shortcode and wrap them in div’s to float them to the left. Just leave the Facebook shortcode without an extra div and it should all line up correctly. Lastly, I wrapped them all into one div.

      I was thinking about doing another post just for display, since I had so many problems. We’ll see !-)

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

  • Recent Posts

    • WP Vanilla Connect
    • Add Twitter Follow Button to WordPress 3.0 with a simple shortcode
    • Add Twitter Share Button to WordPress 3.0 with a simple shortcode
    • Add Facebook Like Button to WordPress 3.0 with a simple shortcode
    • Escape WordPress shortcodes in content with a shortcode
  • Recent Comments

    • Dimo on [Updated] These files can’t be opened. Your Internet security settings prevented one or more files from being opened – Solved
    • casino on Creating a USB bootable disk with a Custom Windows PE image using AIK
    • orthodontists in Middletown on Creating a USB bootable disk with a Custom Windows PE image using AIK
    • Kasey on Creating a USB bootable disk with a Custom Windows PE image using AIK
    • Nickiler on WP Vanilla Connect
  • Categories

    • IT / Windows
    • Plugins
    • Programming & Development
    • Random
    • Shortcodes
    • WordPress
  • Archives

    • January 2012
    • July 2011
    • June 2011
    • September 2010
    • August 2010
    • June 2010
    • May 2010
    • November 2009
ilertech
Proudly powered by WordPress.