Michaelbox's site feed

Tag: shortcode

Just a simple twitter/identica shortcode

by on Apr.22, 2010, under Freedom, Ideas, Passions

 

I real­ized that I will likely ref­er­ence many twit­ter peo­ple in posts and I think it is com­mon cour­tesy to link to their pro­file so that you can go check them out if you want. How­ever, I also want to be lazy and not have to type out their full twit­ter url all the time. Thus I decided that a short­code would be nice and efficient.

With the fol­low­ing 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 user­name in [twit­ter] [/twitter] and have it out­put the full link, like this (Twitter)

Edit

I have since real­ized that this is per­fectly capa­ble of work­ing with identi.ca as well. For word­press users of Identi.ca, copy/paste the fol­low­ing code into your functions.php file. It will work the exact same way regard­ing wrap­ping 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)

2 Comments :, , , more...

My Latest Tweets

MDN is Developer Powered for Web docs, demos and more.

Archives

All entries, chronologically...