Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function get_youtube_kod($post_id=null) {
- // Get the post ID if none is provided
- if($post_id==null OR $post_id=='') $post_id = get_the_ID();
- // Gets the post's content
- $post_array = get_post($post_id);
- $markup = $post_array->post_content;
- // Checks for a standard YouTube embed
- preg_match('#<object[^>]+>.+?http://www.youtube.com/v/([A-Za-z0-9\-_]+).+?</object>#s', $markup, $matches);
- // Checks for any YouTube URL
- if(!isset($matches[1])) {
- preg_match('#http://w?w?w?.?youtube.com/watch\?v=([A-Za-z0-9\-_]+)#s', $markup, $matches);
- }
- // If no standard YouTube embed is found, checks for one embedded with JR_embed
- if(!isset($matches[1])) {
- preg_match('#\[yt url=([A-Za-z0-9\-_]+)]#s', $markup, $matches);
- }
- if(!isset($matches[1])) {
- preg_match('#\[yt url=([A-Za-z0-9\-_]+)[^>]*]#s', $markup, $matches);
- }
- // If we've found a YouTube video ID, create the thumbnail URL
- if(isset($matches[1])) {
- $youtube_kod = $matches[1];
- }
- };
- function youtube_kodic ($post_id=null) {
- echo $youtube_kod;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement