WordPress “Send to Twitter” Button Without Using a Plugin

There are lots of plugins that let you insert a Send to Twitter button into your posts. If you don’t want to use one or if you want to have the Send to Twitter button only in specific posts then you can make a shortcode that you will use only wherever you want it to appear. In order to do that follow these instructions:

  1. Paste the following code in the functions.php file in your theme:
    function twitt() {
    return '<div id="twittit"><a href="http://twitter.com/home?status=Currently reading '.get_permalink($post->ID).'" title="Click to send this page to Twitter!" target="_blank">Share on Twitter</a></div>';
    }
    add_shortcode('twitter', 'twitt');
  2. To use the shortcode, switch the editor to HTML mode and then type in your post/page where you want the button to appear:
    [twitter]

That’s all!

P.S. Don’t forget to style your button at will to make it attractive!

Sources: http://www.wprecipes.com/how-to-create-a-send-this-to-twitter-button, http://www.smashingmagazine.com/2009/02/02/mastering-wordpress-shortcodes/

CATEGORY: Code
DATE: February 12th, 2010 & LEAVE YOUR COMMENT HERE

FILTER BY

Colors