The Chinese version of WordPress now has the built-in function of "using the WordPress Embed function to quickly insert Youku videos": videos can be automatically called once an exclusive line of Youku video address is pasted when writing an article.
For example: I insert the http://v.youku.com/v_show/id_XNTgxNzI3MDcy.html Youku video address in the next line exclusively, you can automatically call Youku video.
However, Embed is used, and there is no problem on the PC end. Because the mobile browser does not support Flash, videos cannot be displayed and played. Currently, videos inserted in iframe mode support mobile phones.
The following describes how to implement it:
Change "use WordPress Embed function to quickly insert Youku video" to the method called in iframe mode.
A bit difficult ,? ? Br/> 1. Confirm that the WordPress is in the Chinese version (it seems that the WordPress version is also available in other languages. If an error message is displayed, delete wp_embed_unregister_handler ('youku)
2. The following code is thrown into the functions. php file of the topic used (note: The code should be placed in <? Php?> )
/**
* "Use the WordPress Embed function to quickly insert a Youku video" is called in iframe mode.
* By zwwooooo | zww. me
*/
// Remove the built-in "using the WordPress Embed function to quickly insert Youku videos" in the Chinese version of WordPress"
Wp_embed_unregister_handler ('youku ');
// Use iframe instead.
Function wp_iframe_handler_youku ($ matches, $ attr, $ url, $ rawattr ){
// If the user supplied a fixed width AND height, use it
If (! Empty ($ rawattr ['width']) &! Empty ($ rawattr ['height']) {
$ Width = (int) $ rawattr ['width'];
$ Height = (int) $ rawattr ['height'];
} Else {
List ($ width, $ height) = wp_expand_dimensions (480,400, $ attr ['width'], $ attr ['height']);
}
$ Iframe = '<iframe width = '. esc_attr ($ width ). 'height = '. esc_attr ($ height ). 'src = "http://player.youku.com/embed /'. esc_attr ($ matches [1]). '"frameborder = 0 allowfullscreen> </iframe> ';
Return apply_filters ('iframe _ youku ', $ iframe, $ matches, $ attr, $ url, $ ramattr );
}
Wp_embed_register_handler ('youku _ iframe', '# http://v.youku.com/v_show/id (.*?). Html # I ', 'WP _ iframe_handler_youku ');
PS: You can change the code of other video websites.
Two methods for quick insertion of Youku videos in PC embed mode and iframe mode on mobile terminals
I will share the code for this function when I help a friend with the theme. I used the previously added mobile terminal to determine whether to use embed or iframe based on the environment.
I am too lazy to explain it in detail. Let's go directly to the code. There is a comment in it: In addition, this code is specially modified for compatibility and supports WordPress in any language.
Code implementation PC embed mobile iframe fast insertion Youku video function
1. in functions. php inserts the following code (some code [such as determining whether to search by mobile] is included in the self-search, where is the source?-okay, I forgot. If you are an original author, contact me)
[Note: All codes in functions. php that are added to the topic should be placed in <php?> Inside]
// Determine whether the mobile device Modify by zwwooooo | zww. me
Function zfunc_is_mobile (){
$ User_agent = $ _ SERVER ['http _ USER_AGENT '];
$ Mobile_agents = Array ("240x320", "acer", "ACO on", "acs-", "abacho", "ahong", "airness", "alcatel ", "amoi", "android", "anywhereyougo.com", "applewebkit/525", "applewebkit/532", "asus", "audio", "au-mic ", "avantogo", "becker", "benq", "bilbo", "bird", "blackberry", "blazer", "bleu", "cdm -", "compal", "coolpad", "danger", "dbtel", "dopod", "elaine", "eric", "etouch", "fly ", "fly _", "fly-", "go. web "," goodaccess "," gradiente "," grundig "," haier "," hedy "," hitachi "," htc "," huawei "," Huchison ", "inno", "ipad", "ipaq", "ipod", "jbrowser", "kddi", "kgt", "kwc", "lenovo", "lg ", "lg2", "lg3", "lg4", "lg5", "lg7", "lg8", "lg9", "lg-", "lge -", "lge9", "longcos", "maemo", "mercator", "meridian", "micromax", "midp", "mini", "mitsu", "mmm ", "mmp", "mobi", "mot-", "moto", "nec-", "netfront", "newgen", "nexian", "nf-browser ", "nintendo", "nitro", "nokia", "nook", "novarra", "obigo", "palm", "panasonic", "pantech", "philips ", "phone", "pg-", "playstation", "pocket", "pt-", "qc-", "qtek", "rover", "sagem ", "sama", "samu", "sanyo", "samsung", "sch-", "scooter", "sec-", "sendo", "sgh -", "sharp", "siemens", "sie-", "softbank", "sony", "spice", "sprint", "spv", "symbian ", "tablet", "talkabout", "tcl-", "teleca", "telit", "tianyu", "tim-", "toshba", "tsm ", "up. browser "," utec "," utstar "," verykool "," virgin "," vk-"," voda "," voxtel "," vx "," wap ", "wellco", "wig browser", "wii", "windows ce", "wireless", "xda", "xde", "zte ");
$ Is_mobile = false;
Foreach ($ mobile_agents as $ device ){
If (stristr ($ user_agent, $ device )){
$ Is_mobile = true;
Break;
}
}
Return $ is_mobile;
}
/// If WordPress is not a Chinese version, add a Youku video to automatically insert Modify by zwwooooo | zww. me
If (get_bloginfo ('language ')! = 'Zh-cn '){
Function wp_embed_handler_youku ($ matches, $ attr, $ url, $ rawattr ){
// If the user supplied a fixed width AND height, use it
If (! Empty ($ rawattr ['width']) &! Empty ($ rawattr ['height']) {
$ Width = (int) $ rawattr ['width'];
$ Height = (int) $ rawattr ['height'];
} Else {
List ($ width, $ height) = wp_expand_dimensions (480,400, $ attr ['width'], $ attr ['height']);
}
$ Embed = sprintf (
'<Embed src = "http://player.youku.com/player.php/sid/4101%s/v.swf" allowFullScreen = "true" quality = "high" width = "'. esc_attr ($ width ). '"height = "'. esc_attr ($ height ). '"align =" middle "allowScriptAccess =" always "type =" application/x-shockwave-flash "> </embed> ',
Esc_attr ($ matches ['video _ id']);
Return apply_filters ('Embed _ youku ', $ embed, $ matches, $ attr, $ url, $ rawattr );
}
Wp_embed_register_handler ('youku ',
'# Https? : // V.youku.com/v_show/id _(? <Video_id> [a-z0-9 _ =-] +) # I ',
'WP _ embed_handler_youku ');
}
/// Use iframe to insert a video to a mobile terminal by zwwooooo | zww. me
If (zfunc_is_mobile ()){
/// If WordPress is a Chinese version, remove the original youku video code and insert it automatically.
If (get_bloginfo ('language ') = 'zh-cn ')
Wp_embed_unregister_handler ('youku ');
//// Added the iframe method for video calling.
Function wp_iframe_handler_youku ($ matches, $ attr, $ url, $ rawattr ){
// If the user supplied a fixed width AND height, use it
If (! Empty ($ rawattr ['width']) &! Empty ($ rawattr ['height']) {
$ Width = (int) $ rawattr ['width'];
$ Height = (int) $ rawattr ['height'];
} Else {
List ($ width, $ height) = wp_expand_dimensions (480,400, $ attr ['width'], $ attr ['height']);
}
$ Iframe = '<iframe width = '. esc_attr ($ width ). 'height = '. esc_attr ($ height ). 'src = "http://player.youku.com/embed /'. esc_attr ($ matches [1]). '"frameborder = 0 allowfullscreen> </iframe> ';
Return apply_filters ('iframe _ youku ', $ iframe, $ matches, $ attr, $ url, $ ramattr );
}
Wp_embed_register_handler ('youku _ iframe', '# http://v.youku.com/v_show/id (.*?). Html # I ', 'WP _ iframe_handler_youku ');
}
2. Usage: directly paste the Youku video address into the content of the article. Be sure to exclusively occupy one line.
-------------
Continue to play with your phone ~ Recently, I am crazy about flash farming ~
Oh, I like those ROM with HALO ......
-------------
In the comments, I reminded WordPress that the mobile device judgment function wp_is_mobile () has been built into WordPress 3.4. I did not pay attention to it, so the code can be reduced:
/// If WordPress is not a Chinese version, add a Youku video to automatically insert Modify by zwwooooo | zww. me
If (get_bloginfo ('language ')! = 'Zh-cn '){
Function wp_embed_handler_youku ($ matches, $ attr, $ url, $ rawattr ){
// If the user supplied a fixed width AND height, use it
If (! Empty ($ rawattr ['width']) &! Empty ($ rawattr ['height']) {
$ Width = (int) $ rawattr ['width'];
$ Height = (int) $ rawattr ['height'];
} Else {
List ($ width, $ height) = wp_expand_dimensions (480,400, $ attr ['width'], $ attr ['height']);
}
$ Embed = sprintf (
'<Embed src = "http://player.youku.com/player.php/sid/4101%s/v.swf" allowFullScreen = "true" quality = "high" width = "'. esc_attr ($ width ). '"height = "'. esc_attr ($ height ). '"align =" middle "allowScriptAccess =" always "type =" application/x-shockwave-flash "> </embed> ',
Esc_attr ($ matches ['video _ id']);
Return apply_filters ('Embed _ youku ', $ embed, $ matches, $ attr, $ url, $ rawattr );
}
Wp_embed_register_handler ('youku ',
'# Https? : // V.youku.com/v_show/id _(? <Video_id> [a-z0-9 _ =-] +) # I ',
'WP _ embed_handler_youku ');
}
/// Use iframe to insert a video to a mobile terminal by zwwooooo | zww. me
If (wp_is_mobile ()){
/// If WordPress is a Chinese version, remove the original youku video code and insert it automatically.
If (get_bloginfo ('language ') = 'zh-cn ')
Wp_embed_unregister_handler ('youku ');
//// Added the iframe method for video calling.
Function wp_iframe_handler_youku ($ matches, $ attr, $ url, $ rawattr ){
// If the user supplied a fixed width AND height, use it
If (! Empty ($ rawattr ['width']) &! Empty ($ rawattr ['height']) {
$ Width = (int) $ rawattr ['width'];
$ Height = (int) $ rawattr ['height'];
} Else {
List ($ width, $ height) = wp_expand_dimensions (480,400, $ attr ['width'], $ attr ['height']);
}
$ Iframe = '<iframe width = '. esc_attr ($ width ). 'height = '. esc_attr ($ height ). 'src = "http://player.youku.com/embed /'. esc_attr ($ matches [1]). '"frameborder = 0 allowfullscreen> </iframe> ';
Return apply_filters ('iframe _ youku ', $ iframe, $ matches, $ attr, $ url, $ ramattr );
}
Wp_embed_register_handler ('youku _ iframe', '# http://v.youku.com/v_show/id (.*?). Html # I ', 'WP _ iframe_handler_youku ');
}
OK, WordPress is really pervasive. Many of you don't need to switch to other partial-door or small-sized blog systems.