viget / craft-video-embed
Generate an embed URL from a YouTube or Vimeo URL
Package info
github.com/vigetlabs/craft-videoembed
Type:craft-plugin
pkg:composer/viget/craft-video-embed
Requires
- php: ^8.2.0
- craftcms/cms: ^5.0.0
Requires (Dev)
This package is auto-updated.
Last update: 2026-06-17 00:07:30 UTC
README
Generate an embed URL from a YouTube or Vimeo URL.
Requirements
This plugin requires Craft CMS 5.0.0 or later.
Installation
To install the plugin, follow these instructions.
-
Open your terminal and go to your Craft project:
cd /path/to/project -
Then tell Composer to load the plugin:
composer require viget/craft-video-embed -
In the Control Panel, go to Settings → Plugins and click the “Install” button for Video Embed.
Using Video Embed
Pass a YouTube or Vimeo URL to the getVideoData method and a VideoData object is returned.
If the plugin is unable to parse the URL, null is returned.
type- If the video isyoutubeorvimeoid- The ID of the videoimage- The thumbnail of the video (only works for Youtube)embedUrl- The URL you would use for the embedurl- The link to the embedded videoisVertical-truefor YouTube Shorts (vertical/portrait) videos, otherwisefalse. Detected from the/shorts/URL form, not the video's true orientation.
Example:
{% set video = craft.videoEmbed.getVideoData('https://www.youtube.com/watch?v=6xWpo5Dn254') %}
{% if video %}
<iframe src="{{ video.embedUrl }}"></iframe>
{% endif %}
Output:
<iframe src="https://www.youtube.com/embed/6xWpo5Dn254?rel=0"></iframe>
YouTube embed URLs include rel=0 so related-video suggestions stay on the same channel rather than promoting unrelated videos.
Customizing URL params
Because embedUrl already carries a query string (YouTube's rel=0, or a Vimeo privacy h hash), add your own player params with Craft's built-in url() function rather than concatenating onto embedUrl. url() preserves the existing params and merges in your own:
<iframe src="{{ url(video.embedUrl, { autoplay: 1, mute: 1 }) }}"></iframe> {# → https://www.youtube.com/embed/6xWpo5Dn254?rel=0&autoplay=1&mute=1 #}
Visit code.viget.com to see more projects from Viget.