WordPress – Create an instant link to Wikipedia

| April 22, 2010 | 1 Comment

I’m often wanting to create quick and useful links to Wikipedia. Obviously, you could add a link manually each time, but wouldn’t an automated system be so much better?

Well, crack open your functions.php file within your theme folder and added the following code…

add_shortcode('wikilink','add_wikilink');
function add_wikilink($paras="",$content="") {
    return '<a href="http://en.wikipedia.org/wiki/'.str_replace(" ","_",$content).'" title="Look up '.$content.' on Wikipedia" title="Look up '.$content.' on Wikipedia" target="_blank" rel="notarget">'.$content.'</a>';
}

Then, simply add the shortcode [wikilink] around any word/words that you wish to look up on Wikipedia.

For example….

The [wikilink]HTC Hero[/wikilink] runs the [wikilink]Android operating system[/wikilink].

This would then produce the following output…

The HTC Hero runs the Android operating system.

The links open in new windows (i.e. target=_blank) and I’ve set rel=nofollow – obviously you can change the above code to modify any of this.

0saves
If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

Tags: , ,

Category: Web Development, Wordpress

About the Author ()

David is the owner and main author of Artiss.co.uk. By day he's a developer for a well known UK retailer, by night he looks after this site and write WordPress plugins.

Comments (1)

Trackback URL | Comments RSS Feed

  1. Rob says:

    Awesome tip, just added it to my blog. The only downside is being careful you don’t link a piece of text that doesn’t have a wikipedia article! Really handy though.

Leave a Reply


By submitting a comment here you agree to our comment policy and grant this site a perpetual license to reproduce your words and name/web site in attribution.