为shortcode标签添加钩子。
- <?php add_shortcode( $tag , $func ); ?>
$tag
(string) (必须) 文章短标记标签
Default: None
$func
(callable) (必须) 发现短标记时调用的函数
Default: None
(none)
wordpress添加优酷视频:
将以下代码拷贝到你主题的functions.php文件中:
- function youku_video($atts, $content=null){
- //添加优酷视频
- return '<p style="text-align: center;"><embed src=http://static.youku.com/v1.0.0149/v/swf/qplayer_rtmp.swf?VideoIDS='.$content.'ID&winType=adshow&isAutoPlay=true" quality="high" width="610" height="460" align="middle" wmode="transparent" allowScriptAccess="never" allowNetworking="internal" autostart="0" type="application/x-shockwave-flash"></embed></p>';
- }
- add_shortcode('youku','youku_video');
本文以一首经典的英文歌曲”Need You Now”为例:
以源码的形式编辑你的文章,将以下代码插入到你文章中
- {youku]XMjM2OTE3ODg4{/youku]
说明:代码中“{” 请替换为“[”
应用实例查看:http://www.shouce.ren/a-1228.html
插入广告代码:
- function ad_shortcode() {
- return '广告代码';
- }
- add_shortcode('ad', 'ad_shortcode');
使用实例:
以“文本”形式编辑文章加入以下代码
- [ad]