KrisChase.com

Pull YouTube Description into WordPress Content

Posted in Web Development on 06.10.2015 by @chasebadkids

You might find yourself needing to dynamically update your WordPress post content with the description of a YouTube video.

I put together the following function to accomplish just that!

This can be a bit tricky due to the fact you’re using the save_post hook from WordPress, while also using the wp_update_post function together which, if not done right can cause an infinite loop.

We can take care of this by unhooking our function, within the save_post call, running our custom function, and then re-initializing our hook.

We get our YouTube Video ID by parsing an ACF (Advanced Custom Fields) field that can either handle a single Youtube ID, or even a complete youtube URL.  This function parses any youtube URL, and then returns the ID of that actual youtube video, then passes it to our description pulling function.

Menu