WordPress增加自动解析youtube视频功能
![]() | ![]() | ![]() | ![]() |
| 【性价之王】 | 【线路之王】 | 【价格之王】 | 【配置之王】 |
| 【免费之王】 | 【香港首推】 | 【梯子之王】 | 【独服之王】 |

前面讲过怎么样张wordpress增加优酷视频解析教程,自己感觉了一下还挺实用的,今天为大家介绍如果给你的博客增加youtube视频解析功能,同时增加短代码,当然,首先你要能打开youtube视频,如果你的博客是面向外国人的,可以这样做,原理其实和增加优酷视频一样的。
一、找解析地址
这个网上的大佬们也有提供,首先我们找到一个youtube的视频地址:(可以百度找一个)
https://www.youtube.com/watch?v=WrY6n0gDuAc
同样的,我们需要只是上面红色部分,因为是要增加短代码,解析地址为:https://www.youtube.com/embed/+上面红色部分
二、增加短代码
我们需要把短代码增加到函数文件中,所有主题的函数文件都是functions.php,但是有一些主题这个文件里的代码非常少,会解析到另外的地址,只要看一下代码就可以,我们在这里面增加以下代码:
function youtube($atts,$content=null,$code=""){ $return = '<div class="video-container"><iframe height="498" width="100%" src="https://www.youtube.com/embed/'; $return .= $content; $return .= '" frameborder="0" allowfullscreen="allowfullscreen"></iframe></div>'; return $return;}add_shortcode('youtube','youtube');function more_button_a(){ if(!current_user_can('edit_posts')&&!current_user_can('edit_pages')) return; if(get_user_option('rich_editing')=='true'){ add_filter('mce_external_plugins','add_plugin'); add_filter('mce_buttons','register_button'); }}add_action('init','more_button_a');function register_button($buttons){ array_push($buttons," ","youku"); array_push($buttons," ","youtube"); return $buttons;}function add_plugin($plugin_array){ $plugin_array['youku'] = get_bloginfo('template_url').'/buttons/more.js'; $plugin_array['youtube'] = get_bloginfo('template_url').'/buttons/more.js'; return $plugin_array; }| 1234567891011121314151617181920212223242526 | function youtube($atts,$content=null,$code=""){ $return = '<div class="video-container"><iframe height="498" width="100%" src="https://www.youtube.com/embed/'; $return .= $content; $return .= '" frameborder="0" allowfullscreen="allowfullscreen"></iframe></div>'; return $return;}add_shortcode('youtube','youtube');function more_button_a(){ if(!current_user_can('edit_posts')&&!current_user_can('edit_pages')) return; if(get_user_option('rich_editing')=='true'){ add_filter('mce_external_plugins','add_plugin'); add_filter('mce_buttons','register_button'); }}add_action('init','more_button_a'); function register_button($buttons){ array_push($buttons," ","youku"); array_push($buttons," ","youtube"); return $buttons;}function add_plugin($plugin_array){ $plugin_array['youku'] = get_bloginfo('template_url').'/buttons/more.js'; $plugin_array['youtube'] = get_bloginfo('template_url').'/buttons/more.js'; return $plugin_array; } |
因为之前我增加了优酷,所以下面的调用图片的地方直接增加就可以了,同时video-container可以在CSS设置样式,同样的,需要去more.js里增加调用按钮图片,打开JS文件,增加:
tinymce.create('tinymce.plugins.youtube', { init : function(ed, url) { ed.addButton('youtube', { title : 'YouTube', image : url+'/images/youtube.png', onclick : function() { ed.selection.setContent('[youtube]' + ed.selection.getContent() + '[/youtube]'); } }); }, createControl : function(n, cm) { return null; }, }); tinymce.PluginManager.add('youtube', tinymce.plugins.youtube);| 123456789101112131415 | tinymce.create('tinymce.plugins.youtube', { init : function(ed, url) { ed.addButton('youtube', { title : 'YouTube', image : url+'/images/youtube.png', onclick : function() { ed.selection.setContent('[youtube]' + ed.selection.getContent() + '[/youtube]'); } }); }, createControl : function(n, cm) { return null; }, }); tinymce.PluginManager.add('youtube', tinymce.plugins.youtube); |
找一个你想要的图标文件,放入buttons文件夹里,后台写文章的面板里就会出有这个图标了。短代码格式如下:
[youtube]9Yam5B_iasY[/youtube]
我是访问不了youtube的,不过让朋友试了一下,可以正常显示视频。
[wordpress]历史优惠活动内容
猜你可能想看的VPS
- 补货 CloudCone→年付$15 1 核 512M 内存 10G 硬全球[VPS测评]
- TripodCloud→圣何塞 CN2 GIA 线路 KVM 年付 38全球[VPS测评]
- DediPath→VPS 全场 4 折 Hybrid Servers 全全球[VPS测评]
- ¥26.98 月 256M 内存 4G 硬盘 100G@3Mbps KV韩国VPS[主机]
- 嘟牛云国庆节特惠活动 多重好礼等你拿 现金 京东 E 卡 256G 固态独立服务器[U]
- 基于 Docker 搭建 Nginx 服务器 在 Docker 中部署 全球[VPS测评]
- php 获取一个月的第一天及最后一天的方法大全全球[VPS测评]
- ZJI→570 元 月-E5 2630L 16GB 480G SSD 5香港VPS[主机]
- js 跳转页面的方法大全全球[VPS测评]
- 2020 年搬瓦工 CN2 GT 网络最新测评,搬瓦工 DC8 机房 C全球[VPS测评]
- 真实测评 tmhhost 洛杉矶 CERA 机房测评 tmhhost 高全球[VPS测评]
- GreenCloudVPS 荷兰阿姆斯特丹机房,2核4G/10Gbps大全球[VPS测评]
- GigsGigsCloud GGC香港 GLOBAL VPS 测评香港VPS[主机]
- MVPS → 3€ 月1C2G25G硬盘3T流量 德国 希腊 瑞典 爱尔全球[VPS测评]
- [优惠]CloudCone 1810 闪购全球[VPS测评]
- 搬瓦工9929 荷兰 VPS → 超稳定省心 → 1G 20G硬盘 1T全球[VPS测评]
- LightCloud 2019 新春: 终身折扣 VDS折扣 充全球[VPS测评]
- 购买香港服务器需要做哪些准备香港VPS[主机]
- 什么是Bootstrap?全球[VPS测评]
- VPS到底有什么用?全球[VPS测评]
- 潮科技|阿里云发布第七代高主频云服务器ECS和含光800云服务器全球[VPS测评]
- 腾讯云免备案海外服务器:高速网络免备案,助力企业出海!全球[VPS测评]
- 30个美容院抖音唯美文案,看到就直接拿去发吧全球[VPS测评]
- 云计算拯救互联网巨头:谁抢跑,谁追赶?全球[VPS测评]
- 深圳市城市交通规划设计研究中心股份有限公司关于与腾讯云计算(北京)有限责全球[VPS测评]
- 外贸无界烟台市有多少跨境电商?烟台跨境电商开发平台,烟台跨境电商选品全球[VPS测评]
- 用玩客云做打印服务器,让你在手机上轻松实现无线打印全球[VPS测评]
- tudcloud:全场7折,香港不限流量VPS,Windows系统,LiWINDOWS
- CombCloud,香港沙田CN2VPS测评,2核1G52元/月,安畅C香港VPS[主机]
- 言車新车|大阳VPS125混动踏板,长续航,代步通勤9980元起全球[VPS测评]
转载请注明原文地址:http://140.238.13.167:12355/read-28267.html











