WordPress Plugin Howto Pt 3

Make WordPress Plugins 3In the previous 2 WordPress Plugin Tutorials I showed you how to create a great WordPress Plugin template you could use to make your own. Here they are if you missed them : WordPress Plugin Howto and WordPress Plugin Howto Pt 2.

The only two capabilities I left out in those tutorials is how to add shortcode capabilities and an uninstall script. In this tutorial I’ll cover that code.

Adding shortcode capabilities to a plugin is pretty easily. If you don’t know what shortcodes are check out WordPress Shortcodes. Basically you just change the widget function we created previously a little bit. You can compare how they are different in the code that follows the video.

You can also download all of the code in a zipped archive if that works better for you. Everything is 100% free to use in any way you like.

Leave any questions or comments below.

Code from the Video

The Widget Function

function widget($args, $instance)


// Splits arguments out and makes them local variables. EXTR_SKIP

// protects any already created local variables

extract( $args, EXTR_SKIP );


// Here if a title is set use it. If not use the default title

$ntt_title = ( get_option( ‘ntt_title’) ) ? get_option( ‘ntt_title’ ) : ‘Follow Me’;


$ntt_facebook = ( get_option( ‘ntt_facebook’) ) ? get_option( ‘ntt_facebook’ ) : ”;


$ntt_twitter = ( get_option( ‘ntt_twitter’) ) ? get_option( ‘ntt_twitter’ ) : ”;



// $before_widget, $after_widget, etc are used for theme compatibility




<?php echo $before_widget; ?>

<?php echo $before_title . $ntt_title . $after_title; ?>



$ntt_feed_icon = plugins_url( ‘images/rss_logo.png’ , __FILE__ );

$ntt_facebook_icon = plugins_url( ‘images/facebook_logo.png’ , __FILE__ );

$ntt_twitter_icon = plugins_url( ‘images/twitter_logo.png’ , __FILE__ );



<!– Prints out the icons and attaches the links to the websites to them –>

<a href=”<?php bloginfo(‘rss2_url’); ?>”><img src=”<?php echo $ntt_feed_icon; ?>” height=”50px” width=”50px”></a>


<a href=”http://www.twitter.com/<?php echo $instance[‘ntt_twitter’]; ?>”><img src=”<?php echo $ntt_twitter_icon; ?>” height=”50px” width=”50px”></a>


<a href=”http://www.facebook.com/<?php echo $instance[‘ntt_facebook’]; ?>”><img src=”<?php echo $ntt_facebook_icon; ?>” height=”50px” width=”50px”></a>


<?php echo $after_widget; ?>




The Short Code Function

function ntt_social_network_sc($args, $content = null)


// Splits arguments out and makes them local variables.


“ntt_twitter” => ‘newthinktank’,

“ntt_facebook” => ‘dbanas2’,

), $atts));


// Assigns the location of the social network logos

// They are located in the plugins folder in an images folder

$ntt_feed_icon = plugins_url( ‘images/rss_logo.png’ , __FILE__ );

$ntt_facebook_icon = plugins_url( ‘images/facebook_logo.png’ , __FILE__ );

$ntt_twitter_icon = plugins_url( ‘images/twitter_logo.png’ , __FILE__ );


/* Saves the location of the icons and attaches the links to the websites to them. */


$ntt_soc_net_content = ‘<a href=”‘;

$ntt_soc_net_content .= get_bloginfo(‘rss2_url’);

$ntt_soc_net_content .= ‘”><img src=”‘;

$ntt_soc_net_content .= $ntt_feed_icon;

$ntt_soc_net_content .= ‘” height=”50px” width=”50px”></a>’;


$ntt_soc_net_content .= ‘<a href=”http://www.facebook.com/’;

$ntt_soc_net_content .= $ntt_facebook;

$ntt_soc_net_content .= ‘”><img src=”‘;

$ntt_soc_net_content .= $ntt_facebook_icon;

$ntt_soc_net_content .= ‘” height=”50px” width=”50px”></a>’;


$ntt_soc_net_content .= ‘<a href=”http://www.twitter.com/’;

$ntt_soc_net_content .= $ntt_twitter;

$ntt_soc_net_content .= ‘”><img src=”‘;

$ntt_soc_net_content .= $ntt_twitter_icon;

$ntt_soc_net_content .= ‘” height=”50px” width=”50px”></a>’;


// Return all of the above for printing in the browser

return $ntt_soc_net_content;


} // End of function ntt_social_network_sc

The Uninstall.php File



// This is checking to make sure the plugin is being uninstalled by a WordPress // Admin. This variable only contains a value if an Admin is activating the

// uninstall script from inside WordPress.


if( !defined( ‘WP_UNINSTALL_PLUGIN’ ) )

exit(); // End the script if accessed by a non-admin


delete_option( ‘ntt_defaults’, ‘ntt_title’);





10 Responses to “WordPress Plugin Howto Pt 3”

  1. Chris says:

    I’ve been waiting for someone like you. You have the best Tutorials on WP Plugins. I recently bought Professional WordPress Plugin Development and have still been looking for stuff that it missed. Would you mind doing a tutorial how to make an rsvp event manger. I’ve downloaded Easy events callendar and hacked it to my liking, I can add events and all details I want, BUT I cant allow registrations for the event. I’m just looking for something simple to add on to that. Name Email Phone. I’ve been trying to figure out how to associate the event with a form, Please help your my hero!!!

  2. Mike Smid says:

    Hi there,

    Nice tutorial, ive got a little question. When doing this little code:

    ), $atts));

    And after the rest of the code i write this
    add_shortcode(‘MS’, ‘TwitterLink’);

    i think it should work right ? but whenever i do [MS twitter=Test] it stil comes up with the standard Mike_Smid. ?

    How could this be.. i can’t get it working.

    Thanks already.


  3. Mike Smid says:

    Hi there,

    Me again.. I found out there is a little typo in your tutorial.
    I changed $atts into $arg and it works..

    let me know if you agree.

    Thanks, again.


    • admin says:

      I don’t know why that worked? There is no typo I just double checked. You have to put quotes around any attributes you send in the shortcode

  4. mark funk says:

    how to i add a button to the text editor in wordpress

  5. mark funk says:

    How do i make and flash audio-player with HTML5 audio tag fallback for mobile phone, tablets & Google TV that in-conjunction with the WordPress audio uploader.

Leave a Reply

Your email address will not be published.