Add Social Links to WordPress Without a Plugin

by admin on May 7, 2010 · 21 comments

Add Social Media Links to Wordpress



One WordPress plugin that almost everybody uses these days is one that lets you share your post on social bookmarking and social media websites. And with the way social media has exploded lately, they’d be silly not too.

While plugins are great, they can also be bloaty, slow loading, require updates and just be a bit of a hassle in general. Luckily it’s very easy to add social links to your WordPress theme without a plugin, just using php and template tags.

So without further ado, here’s the code to add some popular social bookmarking links to your website without the use of a plugin:

Find wherever you’d like to place the code, usually in single.php and page.php right after the content and add in whichever of these you feel:

<a href="http://del.icio.us/post?url=<?php the_permalink() ?>&amp;amp;amp;amp;amp;amp;amp;amp;title=<?php echo urlencode(the_title('','', false)) ?>">del.icio.us</a>
<a href="http://designfloat.com/submit.php?url=<?php the_permalink() ?>&amp;amp;amp;amp;amp;amp;amp;amp;title=<?php echo urlencode(the_title('','', false)) ?>">design float</a>
<a href="http://digg.com/submit?phase=2&amp;amp;amp;amp;amp;amp;amp;amp;url=<?php the_permalink() ?>&amp;amp;amp;amp;amp;amp;amp;amp;title=<?php echo urlencode(the_title('','', false)) ?>">digg</a>
<a href="http://facebook.com/share.php?u=<?php the_permalink() ?>&amp;amp;amp;amp;amp;amp;amp;amp;t=<?php echo urlencode(the_title('','', false)) ?>">facebook</a>
<a href="http://mixx.com/submit?page_url=<?php the_permalink() ?>&amp;amp;amp;amp;amp;amp;amp;amp;title=<?php echo urlencode(the_title('','', false)) ?>">mixx</a>
<a href="http://reddit.com/submit?url=<?php the_permalink() ?>&amp;amp;amp;amp;amp;amp;amp;amp;title=<?php echo urlencode(the_title('','', false)) ?>">reddit</a>
<a href="http://stumbleupon.com/submit?url=<?php the_permalink() ?>&amp;amp;amp;amp;amp;amp;amp;amp;title=<?php echo urlencode(the_title('','', false)) ?>">stumbleupon</a>
<a href="http://technorati.com/faves?add=<?php the_permalink() ?>&amp;amp;amp;amp;amp;amp;amp;amp;title=<?php echo urlencode(the_title('','', false)) ?>">technorati</a>

(Pssst, Thesis users: Don’t place the code where I told you to above, I have special instructions for you folk down below. That code is the same though.)

That’s it. You can do this with any site by looking at their link structure and replacing the url with the permalink and the title with the title echo as you see above.

Thesis Skins Gallery

Spicing the Links Up

An easy way to spice these bookmarking links up is to add icons to them. Just replace the name of the site with

<img src="http://theiconurl" alt="The Title">

(while replacing the variables) and you’ll be on your way. I also suggest adding

<div class="sociallinks">

before the code and

</div>

afterwards, so you can go to your css and style the links as you see fit. Now your theme includes some social bookmarking links and you didn’t need a plugin. Isn’t WordPress great?

Bonus: For Thesis Users

If you use the Thesis theme, which most people reading this website do, then you can do all of this without ever touching your theme files. Just open up custom-functions.php and create a new function to hold these links, replacing the hook with where you’d like the links.

function social_media_links() { ?>

// PLACE THE ABOVE CODE HERE

<?php };
add_action('thesis_hook_after_content', 'social_media_links');

Have any questions or comments? Know of a better way to do this? Want to show off your cool use of social media links? Leave us all a comment!


Previous:

Next: