Hi @Саша Стефано:
Maybe I’m missing something but at first glance it looks like you just need to add a return
statement (I’ve not tested this code so if that’s not it let me know and I’ll dig in to figure it out):
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];
}
return $youtube_kod;
};