Using YouTube API to show videos automatically on WordPress site

“A picture is worth a thousand words”

Moving pictures are even better! Thus, a while ago a friend asked me to help her show the most recent three videos from her YouTube channel on her website. Of course, I could have told her to copy and paste the YouTube URL into the editor, as WordPress provides 30+ embeds put of the box. This solution, however, would require that every time she uploads a video to YouTube, she would then have to manually add the video to her WordPress site.

Instead, I decided using the YouTube API and suggested to pull the videos automatically from her channel and playlist. This avoids manual effort and ensures that the latest videos are always visible on the site. Luckily implementing the YouTube API with WordPress is as easy as pie. I created the following code to show the latest three videos from her YouTube channel on her site:

Of course, requirements change over time. In the meantime, she created 30+ videos and wants to handpick three videos that should be shown on the homepage.

I suggested to create a separate playlist for the homepage videos and show the videos of this playlist instead of the videos of her channel. To reflect the new requirements I changed the code as follows:

Also, she created a private YouTube playlist, to ensure that this playlist will not show within her YouTube playlists, but the videos can be accessed publicly.



Using WP-CLI on VVV without SSH

For years I’ve been using MAMP PRO. After blowing up my database recently, I decided to finally switch over to VVV. Luckily I got a fantastic introduction from Konstantin Obenland during the Contributor Day at the WordCamp Bangkok 2018.

After having touched VVV for almost two weeks, I decided to get my hands dirty this weekend and start migrating my projects over to VVV. While creating the projects (and their virtual hosts) was rather easy, I got stuck with using WP-CLI on VVV. After searching for a while, I stumbled upon a post on Github from Joe Hoyle.

Joe suggested updating the wp-config.php or to use bash functionality to use WP-CLI within VVV without SSH. I decided to follow the first approach and changed the MySQL settings within my wp-config.php from


Please note that changing the DB_HOST only is not enough. Both, the DB_HOST, the DB_USER and the DB_PASSWORD have been changed so that the WP-CLI can be used within VVV without SSH.