With the explosion of social media, networking, and bookmarking services, there are a zillion ways to add “Share This Post” functionality to your WordPress-powered sites. In addition to the myriad services and plugins, we can also add these links directly, using nothing more than a little markup and a few choice PHP snippets. Such individual links provide full control over the selection, layout, and styling of each link without requiring the installation of yet another WordPress plugin.
This article shares SEO-friendly code snippets for ten of the most popular social media sites using completely valid XHMTL-Strict markup. All of the following code snippets feature:
nofollowattributes to conserve pagerank- descriptive
titleattributes for every link - encoded ampersands via
&characters to keep ‘em valid - WordPress template tags for dynamic permalink and title generation
- PHP’s
urlencode()function to encode titles for valid code
Everything here is 100% copy-&-paste, plug-n-play, and ready to go! No editing required! Simply add this code to the desired location in your markup and enjoy! :)
Delicious
Here we have two code snippets for Delicious: the first enables users to bookmark your posts, while the other searches Delicious for links:
<a rel="nofollow" href="http://delicious.com/post?url=<?php the_permalink(); ?>&title=<?php echo urlencode(get_the_title($id)); ?>" title="Bookmark this post at Delicious">Bookmark at Delicious</a>
<a rel="nofollow" href="http://del.icio.us/url?v=1&url=<?php the_permalink(); ?>" title="See all Delicious links to this post">Check Delicious Links</a>
Digg
Ahh, where would we be without Digg.. Here is the code to add a “Digg This!” link to your WordPress posts:
<a rel="nofollow" href="http://digg.com/submit?phase=2&url=<?php the_permalink(); ?>" title="Submit this post to Digg">Digg this!</a>
Here is a “quick-and-dirty” way to enable visitors to easily and quickly tweet your posts with a single click:
<a rel="nofollow" href="http://twitter.com/home?status=<?php echo urlencode("Currently reading: "); ?><?php the_permalink(); ?>" title="Share this article with your Twitter followers">Tweet this!</a>
StumbleUpon
Everyone loves StumbleUpon; they are great for short, intense bursts of decent-quality traffic. Here are two different code techniques to enable your readers to submit your posts to StumbleUpon:
<a rel="nofollow" href="http://www.stumbleupon.com/submit?url=<?php the_permalink(); ?>&title=<?php echo urlencode(get_the_title($id)); ?>" title="Share this post at StumbleUpon">Stumble this!</a>
<a rel="nofollow" href="http://www.stumbleupon.com/submit?url=<?php the_permalink(); ?>&title=<?php _e(urlencode(the_title('','',false))); ?>" title="Share this post at StumbleUpon">Stumble this!</a>
Technorati
Although you can’t really add or share individual posts at Technorati, it is possible to “favorite” entire blogs or even search for content that may be similar to yours. Here is the code to enable visitors to easily add your site to their favorites list at Technorati:
<a rel="nofollow" href="http://technorati.com/faves?add=<?php bloginfo('url'); ?>" title="Add <?php bloginfo('name'); ?> to your Technorati favorites">Add <?php bloginfo('name'); ?> to your Technorati favorites</a>
Here are two different ways to go about searching for similar content, the first uses the post title for the search query, while the other uses the permalink of the post:
<a rel="nofollow" href="http://technorati.com/cosmos/search.html?url=<?php echo urlencode(get_the_title($id)); ?>" title="Search for similar posts on Technorati">Similar Technorati Content</a>
<a rel="nofollow" href="http://technorati.com/cosmos/search.html?url=<?php the_permalink(); ?>" title="Search for similar posts on Technorati">Similar Technorati Content</a>
It seems like all of my non-geek friends and relatives have managed to find me on Facebook. Here’s a way to let them share your posts with each other:
<a rel="nofollow" href="http://www.facebook.com/sharer.php?u=<?php the_permalink();?>&t=<?php echo urlencode(get_the_title($id)); ?>" title="Share this post on Facebook">Share on Facebook</a>
Blinklist
Blinklist is another popular social bookmarking site that may also serve you well. Here is how to add a “Blink This!” link to your posts:
<a rel="nofollow" href="http://blinklist.com/index.php?Action=Blink/addblink.php&url=<?php the_permalink(); ?>&Title=<?php echo urlencode(get_the_title($id)); ?>" title="Share this post on Blinklist" >Blink This!</a>
Furl
Yet another social bookmarking site, Furl is another potentially useful service that may return a few clicks. Here is teh majiik code:
<a rel="nofollow" href="http://furl.net/storeIt.jsp?t=<?php echo urlencode(get_the_title($id)); ?>&u=<?php the_permalink(); ?>" title="Share this post on Furl">Furl This!</a>
And of course, we can’t forget Reddit, a social linking site that is very popular among certain circles. Here’s how to get in on the action:
<a rel="nofollow" href="http://reddit.com/submit?url=<?php the_permalink(); ?>&title=<?php echo urlencode(get_the_title($id)); ?>" title="Share this post on Reddit">Share on Reddit</a>
AddThis
AddThis.com is a popular service that enables users to easily add your posts to a zillion different social sites. Once you have an account, change “USERNAME” in the code below and use the link as a fallback for your readers to share your site with the obscure site of their choice:
<a rel="nofollow" href="http://www.addthis.com/bookmark.php?pub=USERNAME&url=<?php echo get_permalink(); ?>&title=<?php echo urlencode(get_the_title($id)); ?>" title="Bookmark this article at your favorite social media site">Share this post at your favorite social media site</a>
Got More?
While we’re on the subject, what are your favorite social media sites? Did I cover all the most popular sites, or are there others that should be added to this post? Either way, by extrapolating the techniques used in this article, you can add a custom “Share This” link for just about any of your favorite social media services.
{ Hard to believe it’s almost December.. }
More Information
- For more help with writing parameterized query strings, check out my recent article How to Write Valid URL Query String Parameters
20 Responses
Chris Coyier – November 24, 2008
I wish I didn’t have to put them there either. I kind of agree with Louis in that people that actually USE these services use them through their own browser add-ons and hardly ever through little buttons on posts. I personally use a variety of them, and never ever use the buttons. I think the true function is a quick visual reminder. As that, the buttons are pretty useful. If those buttons are going to get you 5 saves to delicious that you wouldn’t have otherwise got, thus pushing you onto the popular page, despite the visual clutter — it was worth it.
Jeff Starr – November 24, 2008
@Donace: Post it anyway! I think there is plenty of room for more social-media link tricks! The referrer code is a good idea, but if you are going for speed, it may be better to “optionize” it.
I agree about the JavaScript — there is no need to rely on it for this level of functionality; we can do everything we need with PHP and a little markup.
As for the link format you are using, you are correct that dropping echo boosts performance (a little), but without the
urlencode()functionality, any post titles that are longer than one word will break the validity of the web page. This feature, I think, is one of the selling points for the techniques provided in this article: every social-media link is 100% valid and SEO-friendly.Louis – November 24, 2008
I wasn’t really talking about the visual clutter that the buttons bring. I was having a more general reflexion on social networks.
I think Graham Smith sums it up quite well when he says:
All design and visual nuisance appart, I feel that it’s not the websites role to link the social services. If you are subscribed to a social service, you want to be able to use it on any website. You can’t expect every and each website on the internet to have the links ready for you.
This decentralized approch is not working in my opinion.
Simon – November 24, 2008
@Jeff, haha yes it’s true I was lucky enough to be “discovered” by Anthony who’s running some things on the site.
Back to the topic, true I think browser based stuff solutions work best for you personally. Though a button almost always remembers people to vote and so a combined thing will always work best. I’m actually just reconsidering some things on social bookmarking end.
Donace – December 17, 2008
*looks around* I heard my name…..
Though yes the clickthough on these buttons are more for the occasional social media user (I would class myself as one). So once I read an article and I thought it was good, I would think ‘ohh click buttons!’
Kim Woodbridge – December 17, 2008
Hi Jeff,
The people who visit my site are not that tech savvy (well except for Donace) and I’ve found that the social media links are used. Not a lot but enough to justify having them there.
I don’t use them though – I use my own bookmarklets like Graham mentioned.
And I will definitely bookmark this in my list of things I’ve got to try.
Jeff Starr – December 17, 2008
@Kim: I find that people will click on the social media links if the article is worth it and the links are available. Of course, as you suggest, the more savvy users are equipped with their own bookmarking and sharing methods and will share the content as they see fit and according to their own purposes. The nice thing about these particular link examples is their ease of implementation and valid syntax. Great to see you again — thanks for dropping in and sharing your thoughts! :)
@Donace: Good to see your “reputation radar” is working well and in full effect! ;)
Silver Firefly – March 16, 2009
Thanks for this article.
I’m savvy and I never use browser based social bookmarking buttons. I always use the ones that are provided on the website I’m browsing. That’s because I’m not a power social bookmarker.