Wordpress Widgets 101: Social Media Links

Last Updated on Thursday, 6 November 2008 10:16 Written by webguyatwork Thursday, 6 November 2008 10:16

I’ve finally taken the plunge into learning how Wordpress development works.  I don’t claim to be an expert, but the following information might be useful to someone with very little programming experience but the desire to add a new social media widget to their blog site.

First off, I download the Social Media Page plugin from Philip Norton, found on the Wordpress Plugin Directory.  The installation instructions are fairly straight forward, so I won’t reiterate them here.  Basically, after the install, you enable the plugin and go add your social media site login names.  Doing so will store the entries in a new database table that was created when you initialized the plugin.

I realized that plugin was only build to display your links on a new page, and I wanted to instead display them in the sidebar as you now see over there on the side of the page.  To accomplish this, open the social-media-page.php file and insert the following lines toward the bottom of the file:

/* Widget section added by Brian Richmond – 4Minds Internet Group
Replace the existing social-media-page.php to get widget functionality in your blog site
*/
function widget_social_media() {
?>
<h2 class=”widgettitle”>Social Media</h2>
<?php echo smpCreatePage(); ?>
<?php
}

function init_social_media() {
register_sidebar_widget(__(‘Social Media’), ‘widget_social_media’);
}

add_action(“plugins_loaded”, “init_social_media”);

This code will register a new sidebar widget that you can add using the Wordpress administrator.  Once you upload the new file to your server, the widget should be immediately available to add to your site.  If you have configured your usernames in the Social Media Page properties, the links will show up immediately on the page.

Note that I’ve slightly modified the code inside of the smpCreatePage() function to result in the output that I wanted to see on my site.  Feel free to play around with the output to match your own needs.  Let me know if you’ve found this tutorial useful.



7 Comments

  1. Wonder   |  Thursday, 06 November 2008 at 9:20 pm

    Wow, even I’m starting to “get it”. Thanks a ton for this post. I’ve been struggling with widgets for awhile. I think, thanks to your post, the light is finally starting to blink.

    Thanks for the Notepad headsup too. Looks much improved over the last time I tried it.

  2. webguyatwork   |  Thursday, 06 November 2008 at 9:46 pm

    I can’t take full credit. I had help from other sites, but this does provide a useful stepping stone to diving into Wordpress development. One thing I learned while working on this was that the widget code needs to be part of an existing plugin. I might find out otherwise as I try other things, and I’ll let everyone know what I find out.

  3. Social Media Widget Update - 4Minds Technology Blogs   |  Friday, 07 November 2008 at 9:49 am

    [...] Media Widget Update Nov.07, 2008 in Uncategorized This is a follow-up to yesterday’s post on building a sidebar widget for the “Social Media Page” plugin from Philip Norton.  [...]

  4. Stephanie   |  Monday, 02 March 2009 at 3:01 pm

    Hi! I don’t know why but it gave me a fatal error when I added the code to the bottom of the file…?

  5. webguyatwork   |  Tuesday, 03 March 2009 at 10:00 am

    Stephanie, did you download the Social Media Page plugin that I linked to in the article? In my code, the call to “smpCreatePage” is directly linked to that plugin, otherwise you may get this error.

    Also, looking back at my code here, I realize that it’s only partially there. I uploaded the full widget file for download here: http://blog.4minds.com/?attachment_id=338

    Let me know if you still have issues. Send me your blog link and I’ll take a look as best I can. Good luck!

  6. Brian   |  Thursday, 29 July 2010 at 1:28 pm

    Editing a plugin is a bad idea.

    What happens when the plugin is updated? You’ll have to go in there and edit it again every time. That can become more of a hassle than just sucking it up and accepting what the plugin maker gives you.

    Plus if you request it enough, I’m sure they’ll be happy to add functionality to it.

    I also think Social Media Page now has a sidebar widget anyway.

    Again – Editing plugins can cause more damage than good.

  7. webguyatwork   |  Thursday, 29 July 2010 at 10:44 pm

    This is the disclaimer that I probably should have put into the article to begin with, so thanks for mentioning it. I’ve avoided updating this particular plugin for the very reason you mentioned. But I’ve found the hard way that it only takes a click and a single confirmation to update and lose the changes. Perhaps contacting the original developer is a better option if you don’t have the means to create your own separate plugin from scratch.

    Thanks again for the comment. It’s been a while since I’ve really looked at what new features the plugin has now. I’ll be sure to check it out.

Leave a Reply