WordPress – Shortcode API
November 29th, 2010 at 01:40pm Jason 40 views
This function has been used since WP 2.5, for some more details: http://codex.wordpress.org/Shortcode_API
Here I will show you some usages:
1. MP3 Player
function mp3player($atts, $content=null){ extract(shortcode_atts(array("auto"=>'0'),$atts)); return '<embed src="'.get_bloginfo("template_url").'/mp3player.swf?url='.$content.'&autoplay='.$auto.'" type="application/x-shockwave-flash" wmode="transparent" allowscriptaccess="always" width="400" height="30">'; } add_shortcode('mp3','mp3player');
You need download mp3player.swf first.
When you write a post, use the shortcode [mp3]URL[/mp3], and [mp3 auto="1"]URL[/mp3] for autoplay.
2. Google Docs
function docsGoogle($atts, $content=null){ return '<p style="text-align: center;"><iframe style="border-style: none;" src="http://docs.google.com/viewer?url='.$content.'&embedded=true" width="600" height="300"></iframe></p>'; } add_shortcode('docs','docsGoogle');
3. Flash
function swf_player($atts, $content=null){ return '<p style="text-align: center;"><embed type="application/x-shockwave-flash" width="480" height="360" src="'.$content.'"></embed></p>'; } add_shortcode('swf','swf_player');
Entry Filed under: WordPress Tagged with: blog code PHP wordpress
Hot Posts Hot Comments Hot Tags
- apartment bbpress blog class CMS code CSS div dream english friends girl Google hot Hot Dog html job JS life lines love Madonna menu Michael Jackson movie oral english PHP plugin saying school sexy site student students submenu success tags teacher teaching txt university video website widget wordpress





1 Comment Add your own
1. WordPress 短代码的使&hellip | November 29th, 2010 at 2:21 pm
[...] NAME – 设定代码名字 CODE – 代码主体框架 SHORTCODE – 要使用的短代码延伸阅读:http://www.wheatnotes.com/2010/11/wordpress-shortcode-api/ google_ad_client = "pub-0467901677192331"; /* 468×15, 创建于 10-5-24 */ google_ad_slot = [...]
Leave a Comment
Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">
Trackback this post | Subscribe to the comments via RSS Feed