Last update at :2024-02-07,Edit by888u
I have talked about how to add Youku video parsing tutorial to WordPress. I feel that it is quite practical. Today I will introduce to you how to add YouTube video parsing function to your blog and add short codes at the same time. Of course, first of all, you must be able to Open a YouTube video. If your blog is for foreigners, you can do this. The principle is actually the same as adding a Youku video.
1. Find the resolution address
The big guys on the Internet also provide it. First, we find a YouTube video address: (You can find one on Baidu)
https://www.youtube.com/watch?v=WrY6n0gDuAc
Similarly, we only need the red part above because we need to add a short code. The parsing address is: https://www.youtube.com/embed/+the red part above
2. Add short code
We need to add the short code to the function file. The function file of all themes is functions.php, but some themes have very little code in this file and will be parsed to another address. Just look at the code. , we add the following code here:
function youtube($atts,$content=null,$code=""){ $return = ''; 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; }Because I added Youku before, you can just add the place where you call the image below. At the same time, the video-container can be styled in CSS. Similarly, you need to add the call button image in more.js and open the JS file. , increase:
tinymce.create('tinymce.plugins.youtube', { init: function(ed, url) { ed.addButton('youtube', { title: 'YouTube', image : url+'/images/youtube.png', onclick : function() { ed.selection.setContent(''); } }); }, createControl : function(n, cm) { return null; }, }); tinymce.PluginManager.add('youtube', tinymce.plugins.youtube);Find an icon file you want, put it in the buttons folder, and the icon will appear in the background article writing panel. The short code format is as follows:
I can't access YouTube, but I asked a friend to try it and the video can be displayed normally.
Recommended site search: website space purchase, how to check ip address, domain name space, foreign server vps, foreign space rental, free cn domain name registration, Hong Kong host high defense, personal free space, server high defense Hong Kong cloud host,
p>
发表评论