Getting the YouTube tag with PHP

The Solution

The Explanation

The piece PHP code above will allow you to extract the ID number inside of various youtube URLs. This helps you so that your client isn’t required to remember which URL will work when the post a custom field. Here is how we utilized it recently inside the WordPress Loop:

NOTE: The IMG is being pulled from YouTube as well. It is automatically getting the thumbnail that youtube provides.


URLs this works for: