In a recent site I worked on, my task was to display values of custom fields attached to a CPT. One of these custom fields is a URL field named “YouTube Video” added via Types plugin. I tried a couple of free plugins from the WP repository including WP YouTube Player that would display YouTube video by wrapping the URL in shortcodes. Unfortunately they did not work when the URL value is a shortcode inserted via Views. What worked was iThemes VidEmbed plugin.
Here is the code to display YouTube video with player when the video URL has been entered in a custom field attached to a CPT in WordPress.
where youtube-link is the name of URL field in which YouTube URL (Ex.: https://www.youtube.com/watch?v=m0iiTk3MQ3k) will be entered. In the above width and height values can of course be adjusted. Also the field name should be changed.
With this View Template (per the screenshot at the top of this post) set as the field to display in grid layout for the CPT listing via a View (screenshot), here’s the output: