我使用此代码向Wordpress添加帖子:
$new_post = array(
\'post_title\' => $title,
\'post_content\' => "test https://www.youtube.com/watch?v=4g3e8XwVIYc https://youtu.be/LPpW_8c5jE4",
\'post_status\' => \'publish\',
\'post_author\' => $author,
\'post_type\' => \'post\'
);
wp_insert_post($new_post, true);
问题是youtube链接不会被嵌入。但是,如果我手动将其发布到WordPress,则链接将自动嵌入。要让WordPress自动将youtube URL转换为嵌入式视频,我需要做什么?
该网站的另一个答案是使用wp\\u insert\\u post(),但考虑到youtube URL语法多种多样,我如何从帖子内容中提取youtube URL。WP Codex上的嵌入页面表示只需将“视频URL放入内容区域”。我很惊讶在使用wp\\u insert\\u post()时没有自动嵌入所有youtube视频的功能。。。除非我错过了什么?
谢谢