你好@Саша Стефано:
也许我遗漏了什么,但乍一看,你只需要添加一个return
语句(我还没有测试过这段代码,所以如果不是,请告诉我,我会深入研究解决):
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;
};