Skip to content

Instantly share code, notes, and snippets.

@yuikns
Last active December 15, 2015 05:39
Show Gist options
  • Save yuikns/5210906 to your computer and use it in GitHub Desktop.
Save yuikns/5210906 to your computer and use it in GitHub Desktop.
<?php
/**
*Plugin Name: Wikipedia_Entry_Inserter
*Version: 0.1
*Plugin URI: http://argcandargv.com
*Description: insert wikipedia entry with [wiki] and [/wiki]
*Author: Yu Jing
*Author URI: http://argcandargv.com/
*/
function Wikipedia_Entry_Inserter($outer){
if(!is_singular()){ return $outer; }
$outer = preg_replace('/\[wiki\](.+?)\[\/wiki\]/','<a href="//en.wikipedia.org/wiki/$1" rel="nofollow" title="$1" target="_blank">$1</a>', $outer);
$outer = preg_replace('/\[wiki:zh\](.+?)\[\/wiki:zh\]/','<a href="//zh.wikipedia.org/wiki/$1" rel="nofollow" title="$1" target="_blank">$1</a>', $outer);
return $outer;
}
add_filter('the_content', 'Wikipedia_Entry_Inserter');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment