Php 如何获取帖子的第一个嵌入内容
我正在尝试从帖子中获取第一个嵌入url。 我知道wordpress自动嵌入了它们,但找不到一种方法来获取 嵌入Php 如何获取帖子的第一个嵌入内容,php,wordpress,youtube,embed,vimeo,Php,Wordpress,Youtube,Embed,Vimeo,我正在尝试从帖子中获取第一个嵌入url。 我知道wordpress自动嵌入了它们,但找不到一种方法来获取 嵌入 此函数将返回第一个[embed]短代码: function sofa_get_embed_shortcode($content) { preg_match('/\[embed(.*)](.*)\[\/embed]/', $content, $matches); return $matches; } 将$post->post\u content作为$content变量传
此函数将返回第一个
[embed]
短代码:
function sofa_get_embed_shortcode($content) {
preg_match('/\[embed(.*)](.*)\[\/embed]/', $content, $matches);
return $matches;
}
将
$post->post\u content
作为$content
变量传递,您将收到一个找到的[embed]
短代码数组。自Wordpress 2.9以来,已包含wp\u oembed\u get函数
例如:
<?php $embed_code = wp_oembed_get($url); ?>
以下是函数的链接,用于获取嵌入:
WP是否替换了。。。有嵌入标签吗?我希望用户只粘贴URL。
<?php $embed_code = wp_oembed_get($url); ?>