I use this code to add a post to 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);
The problem is that youtube links will not be embedded. However, if I post it manually to WordPress then the links will be automatically embedded.
What do I need to do in order for WordPress to automatically transform youtube URL to embedded videos?
Another answer from this site says to use wp_insert_post() but how would I extract youtube URL's from the post content considering there are various youtube URL syntaxes. Embeds page on WP Codex says to just put the "video URL into the content area". I am surprised there is not a function to automatically embeds all youtube videos when using wp_insert_post() ...unless I am missing something?