WordPress WordPress Plugins

How to import liked YouTube videos into WordPress

The WordPress plugin described in this article has been retired and is no longer active on my personal website. An archive of the work still exits at this GitHub repo.

If you visit my personal website you will notice the homepage is setup to show a random video I liked on YouTube.

I’ve also given my liked videos their own page so you can see what videos I’ve liked in chronological order.

Here take a look at these screenshots. They’ll show you how both sections look:

Homepage — Source: hudsonatwell.co/
Archive Page — Source: hudsonatwell.co/liked-videos/

I love using YouTube as a curation tool and I never quite know what I want to do on my personal site.

Because music is such a big part of my life, I want to share all the great tracks I discover with others. WordPress is a great way to do this, and I can also leverage their REST API and native RSS feeds for syndicating my liked videos to other social channels.

How I Import Liked Videos into WordPress

To import liked videos into WordPress I built a plugin that accesses the YouTube API, regularly via cron, and imports liked content into a WordPress custom post type.

You can find my project’s GitHub repository here, for downloads and contributions.

Setting up the plugin

There are very minimal requirements to setting this plugin up. Have look below at the settings area and the place where we store imported videos:

Liked videos imported over time

Though this asset is great at importing, it doesn’t really come with any front-end features. Front-end integration requires a few manual steps and depending on how far you want to take it, maybe some custom coding as well.

Linking to liked videos

Once the plugin is set up and importing videos into a custom post type, you can link directly to that post-type’s archive by adding the following permalink name onto your website’s base URL: /liked-videos/

So for quick and easy access to an archive, the full like will look like this:

https://hudsonatwell.co/liked-videos/

Custom Front-end Styling

In order to create custom styling, consider creating an archive template for the liked-videos custom post type.

Here’s an example of my website’s custom archive page’s PHP code:

https://gist.github.com/atwellpub/f0d25379d1e58abbcb1fc2fc548e1329#file-archive-liked-videos-php

Note: archive-liked-videos.php is basically a clone of my WordPress theme’s archive.php file. This file normally sits inside the theme’s base directory. That’s also where we will create our new file archive-liked-videos.php.

You most likely will not want to use the code I have above. Instead, find your own theme’s archive.php file in your theme’s base directory file; copy, paste & modify that file’s contents into a new file called archive-liked-videos.php.

Another thing you may be wondering is, “How did you add a rotating video to your homepage?

How I added a rotating liked video to my homepage:

In order to add the random video embed to my homepage I wrote a PHP snippet below to create a WordPress shortcode that looks like this: [latest-video].

I then added the above shortcode to my homepage’s content area.

Here’s the PHP code I wrote to support the shortcode [latest-video] and allow it to be used inside of content:

https://gist.github.com/atwellpub/cbfa883254c35ff3df99514c50211ff7#file-functions-php

Please note: The above PHP code should be placed inside your theme’s functions.php file or into a custom plugin. It is not included with the plugin found on the repo.

Thank you for reading this article! I sell very powerful & effective WordPress plugin products and take on contracting gigs through the Codeable.io Agency.

Thanks again for reading!

Leave a Reply

Your email address will not be published. Required fields are marked *