Just a simple twitter/identica shortcode
by tw2113 on Apr.22, 2010, under Freedom, Ideas, Passions
I realized that I will likely reference many twitter people in posts and I think it is common courtesy to link to their profile so that you can go check them out if you want. However, I also want to be lazy and not have to type out their full twitter url all the time. Thus I decided that a shortcode would be nice and efficient.
With the following code,
<?php
function twitter_shortcode( $atts, $content = null ) {
return '<a href="http://twitter.com/' . $content . '" title="' . $content . '\'s Twitter Profile">' . $content . '</a>';
}
add_shortcode('twitter', 'twitter_shortcode');
?>
I can wrap a username in [twitter] [/twitter] and have it output the full link, like this (Twitter)
Edit
I have since realized that this is perfectly capable of working with identi.ca as well. For wordpress users of Identi.ca, copy/paste the following code into your functions.php file. It will work the exact same way regarding wrapping the user ID
<?php
function identica_shortcode( $atts, $content = null ) {
return '<a href="http://identi.ca/' . $content . '" title="' . $content . '\'s Identi.ca Profile">' . $content . '</a>';
}
add_shortcode('identica', 'identica_shortcode');
?>
Like so: (Identica)




April 23rd, 2010 on 4:07 pm
This is a really awesome shortcode. I’m redesigning Arbenting right now and am definitely going to work this into my new theme. Thanks!
April 23rd, 2010 on 6:53 pm
thank you for the kind words Angie. Glad the shortcode will prove useful despite being so basic. Now to come up with more that solve regular problems.