Type something to search...
How to embed videos in WordPress?

How to embed videos in WordPress?

To embed a video in WordPress, copy the video's URL from a site like YouTube or Vimeo and paste it on its own line in the block editor. WordPress automatically turns it into an embedded player. You can also use the dedicated YouTube, Vimeo, or general Embed blocks, or upload a video file directly with the Video block if you want to host it yourself.

Video is one of the most engaging types of content you can add to a site, whether that's a tutorial, a product demo, or a customer testimonial. WordPress makes embedding easy, but there are a few choices that affect speed, privacy, and appearance. This guide covers embedding from video platforms, uploading your own videos, embedding in widgets and templates, handling responsive sizing, and improving performance.

Embedding vs. Uploading Videos

There are two basic ways to show a video on your WordPress site.

Embedding From a Video Platform

The video lives on a service like YouTube or Vimeo, and your page shows their player. This is the approach most sites should use:

  • Saves bandwidth and storage: The video platform streams the file, not your server.
  • Adaptive quality: Platforms adjust video quality based on each viewer's connection.
  • Better performance: Your hosting account isn't slowed down by large video files.
  • Extra reach: Your videos can be discovered on the platform itself.

Uploading (Self-Hosting)

The video file is stored in your WordPress Media Library and played with the browser's built-in player. This gives you full control and no third-party branding, but:

  • Video files are large and can quickly fill up your hosting storage.
  • Many hosts limit upload sizes and bandwidth.
  • Viewers with slow connections may struggle, since there's no adaptive streaming by default.

Self-hosting works well for short clips, such as a background video or a few seconds of product footage. For anything longer, a video platform is usually the better choice.

How to Embed a YouTube Video

YouTube is the most common source of embedded videos, and WordPress supports it out of the box.

Method 1: Paste the URL

  1. Copy the video URL: On YouTube, click Share below the video and copy the link, or copy the URL from your browser's address bar.
  2. Open your post or page in the block editor.
  3. Paste the URL into an empty paragraph on its own line.
  4. Let WordPress convert it: The URL turns into a YouTube embed block with a preview.

That's it. WordPress uses a technology called oEmbed to fetch the player from YouTube automatically.

Method 2: Use the YouTube Embed Block

  1. Click the + block inserter.
  2. Search for "YouTube" and select the YouTube embed block.
  3. Paste the video URL into the field and click Embed.

Customizing the Embed

Select the embed block to see options in the toolbar and sidebar:

  • Caption: Add a short description below the video.
  • Alignment: Choose wide or full width if your theme supports it.
  • Resize for smaller devices: Keeps the video's aspect ratio on mobile. Leave this on in most cases.

To start a YouTube video at a specific time, add ?t= with the number of seconds to the URL, for example https://youtu.be/VIDEO_ID?t=90.

How to Embed a Vimeo Video

Vimeo works exactly the same way:

  1. Copy the video URL from Vimeo.
  2. Paste it on its own line in the editor, or use the Vimeo embed block.

Vimeo's paid plans offer extra privacy controls, such as only allowing a video to be embedded on specific domains. If you use that feature, make sure your site's domain is added in the video's privacy settings on Vimeo, or the embed will show an error.

Other Supported Video Services

WordPress supports embeds from many services through oEmbed, including:

  • YouTube
  • Vimeo
  • TikTok
  • Dailymotion
  • VideoPress
  • Several other providers listed in the WordPress embeds documentation
  • Social platforms such as Facebook and Instagram (these require an access token and usually a plugin)

The general Embed block accepts a URL from any supported provider. If WordPress can't embed a link, it will say so and offer to convert it into a regular link.

How to Embed a Video Using Embed Code

Sometimes you'll want more control than a URL gives you, such as specific player parameters. In that case you can paste the platform's embed code:

  1. On YouTube, click Share, then Embed, and copy the iframe code. Adjust options like Enable privacy-enhanced mode before copying.
  2. In WordPress, add a Custom HTML block.
  3. Paste the code and click Preview to check it.

A typical YouTube embed looks like this:

<iframe
  width="560"
  height="315"
  src="https://www.youtube-nocookie.com/embed/VIDEO_ID?rel=0"
  title="YouTube video player"
  frameborder="0"
  allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
  referrerpolicy="strict-origin-when-cross-origin"
  loading="lazy"
  allowfullscreen
></iframe>

A few useful details:

  • The youtube-nocookie.com domain is YouTube's privacy-enhanced mode, which limits tracking until the viewer plays the video.
  • rel=0 limits suggested videos at the end to those from the same channel.
  • loading="lazy" tells the browser not to load the iframe until it's close to the viewport.

Note that only users with the unfiltered_html capability (Administrators and Editors on single sites) can save iframes in a Custom HTML block. Other roles will have the code stripped for security.

How to Upload and Self-Host a Video

For short videos, you can upload them directly.

  1. Prepare the file: Use MP4 with H.264 video and AAC audio for the widest browser support. WebM is also well supported. Compress the file before uploading.
  2. Add a Video block: Click the + inserter and choose Video.
  3. Upload the file: Click Upload, or choose Media Library to use an existing file.
  4. Configure the settings in the sidebar:
    • Autoplay: Starts automatically. Browsers only allow autoplay when the video is muted.
    • Loop: Repeats continuously.
    • Muted: Starts with sound off.
    • Playback controls: Shows play, pause, and volume controls.
    • Play inline: Plays inside the page on mobile instead of going full screen.
    • Preload: Choose None or Metadata to avoid loading the whole file on page load.
    • Poster image: A still image shown before the video plays.
  5. Add tracks (optional): Upload a .vtt subtitle or caption file for accessibility.

Upload Size Limits

If your upload fails, your server's maximum upload size is probably too small. You can see the current limit on the upload screen at Media > Add New Media File. Raising it depends on your host; some let you change upload_max_filesize and post_max_size in the control panel's PHP settings. If you can't raise it, that's a strong sign the file is better hosted on a video platform.

Background Videos With the Cover Block

The Cover block can use a video as a background, which is popular for hero sections:

  1. Add a Cover block.
  2. Click Upload or Media Library and choose a short video.
  3. Add a heading and button on top.

Keep background videos short (a few seconds that loop), silent, and heavily compressed.

Making Embedded Videos Responsive

Modern WordPress themes handle responsive embeds well, especially when the Resize for smaller devices option is enabled on embed blocks. If your theme is older or you're using a Custom HTML iframe, add this CSS to make iframes scale properly:

.entry-content iframe[src*="youtube"],
.entry-content iframe[src*="youtube-nocookie"],
.entry-content iframe[src*="vimeo"] {
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
}

Add it through Appearance > Editor > Styles > Additional CSS in block themes, or Appearance > Customize > Additional CSS in classic themes. Adjust .entry-content to match your theme's content wrapper if needed.

For classic themes, developers can also enable WordPress's built-in responsive embed styles:

function mytheme_setup_responsive_embeds() {
    add_theme_support( 'responsive-embeds' );
}
add_action( 'after_setup_theme', 'mytheme_setup_responsive_embeds' );

Embedding Videos in Widgets, Templates, and Code

In Widget Areas

In block-based widget areas (Appearance > Widgets), add a YouTube, Vimeo, Embed, or Video block, just like in a post. In block themes, open Appearance > Editor and add the block to a template or template part.

In PHP Templates

In classic theme templates, you can use wp_oembed_get() to fetch the embed HTML for a URL:

<?php
$sajjad_video_url  = 'https://www.youtube.com/watch?v=VIDEO_ID';
$sajjad_video_html = wp_oembed_get( $sajjad_video_url, array( 'width' => 800 ) );

if ( $sajjad_video_html ) {
    echo '<div class="video-wrapper">' . $sajjad_video_html . '</div>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
?>

wp_oembed_get() returns markup from a trusted oEmbed provider, which is why it's output directly here. For self-hosted files, use wp_video_shortcode():

<?php
echo wp_video_shortcode(
    array(
        'src'     => esc_url( 'https://example.com/wp-content/uploads/2026/09/demo.mp4' ),
        'poster'  => esc_url( 'https://example.com/wp-content/uploads/2026/09/demo-poster.jpg' ),
        'preload' => 'metadata',
        'width'   => 1280,
        'height'  => 720,
    )
);
?>

Using the Video and Embed Shortcodes

The classic [video] and [embed] shortcodes still work, which can be handy in page builders or the Classic Editor:

[embed]https://www.youtube.com/watch?v=VIDEO_ID[/embed]
[video src="https://example.com/wp-content/uploads/2026/09/demo.mp4" poster="https://example.com/wp-content/uploads/2026/09/demo-poster.jpg"]

Improving Performance With Video Embeds

Each YouTube or Vimeo iframe loads a noticeable amount of JavaScript, even if nobody presses play. A page with several embeds can feel sluggish. Some ways to reduce the impact:

  • Lazy load iframes: WordPress adds loading="lazy" to iframes automatically in most cases, so embeds below the fold don't load until needed.
  • Use a facade (click-to-load): Show a lightweight thumbnail with a play button, and only load the real player when clicked. Plugins such as WP YouTube Lyte and performance plugins like WP Rocket and Perfmatters offer this feature.
  • Limit the number of videos per page: Instead of ten embeds, consider one featured video and links to the rest.
  • Compress self-hosted videos: Tools like HandBrake can reduce file size significantly without obvious quality loss.

Our guide to speeding up WordPress covers more performance techniques if you want to dig deeper.

Privacy and Accessibility Considerations

Privacy

Embedded players from third parties can set cookies and collect data. If you're subject to privacy laws such as the GDPR:

  • Use YouTube's privacy-enhanced mode (youtube-nocookie.com) or Vimeo's "do not track" option (?dnt=1).
  • Consider a consent tool that blocks embeds until a visitor agrees, which many cookie consent plugins support.
  • Mention embedded content in your privacy policy.

Accessibility

  • Add captions: Upload caption files for self-hosted videos, and enable captions on YouTube or Vimeo.
  • Avoid autoplay with sound: It's disruptive and blocked by most browsers anyway.
  • Use a descriptive title: For iframes, the title attribute helps screen reader users understand what the embed is.
  • Provide a transcript: For tutorials or interviews, a text transcript helps everyone, including search engines.

Troubleshooting Video Embeds

The URL shows as a plain link: Make sure it's on its own line with no other text, and that it's a direct link to a video rather than a channel or playlist page. Check that the provider is supported.

"Sorry, this content could not be embedded": The provider may block embedding for that video, or the URL is incorrect. Try the platform's share link.

The video appears tiny or cropped: Enable Resize for smaller devices on the block, or add the responsive CSS above.

The iframe disappears after saving: Your user role lacks the unfiltered_html capability. Ask an Administrator to add it, or use an embed block instead.

Upload fails: The file exceeds your upload limit. Compress it, ask your host to raise the limit, or use a video platform.


FAQ: Embedding Videos in WordPress

Copy the YouTube URL and paste it on its own line in the block editor. WordPress automatically converts it into an embedded player.

For most videos, use YouTube, Vimeo, or another video platform. Uploading large videos can slow your site and use up hosting storage and bandwidth. Self-hosting is best for short clips.

Enable Resize for smaller devices on the embed block. For older themes or custom iframes, add CSS that sets the iframe width to 100 percent with a 16:9 aspect ratio.

Yes, but browsers only allow autoplay for muted videos. In the Video block, enable both Autoplay and Muted. Use autoplay sparingly.

Only users with the unfiltered_html capability, typically Administrators and Editors, can save iframes. Use an embed block instead or ask an Administrator to add the code.

Each embed loads extra scripts from the video platform. Lazy loading and click-to-load facades greatly reduce the impact, especially on pages with several videos.

Add a YouTube, Vimeo, Embed, or Video block to your widget area under Appearance > Widgets, or to a template part in the Site Editor for block themes.


Conclusion

Embedding videos in WordPress is usually as easy as pasting a URL. For YouTube, Vimeo, and many other services, WordPress handles the player automatically, and the dedicated embed blocks give you captions, alignment, and responsive sizing. When you need more control, a Custom HTML block with the platform's embed code or the PHP functions wp_oembed_get() and wp_video_shortcode() have you covered.

For the best results, host longer videos on a video platform, keep self-hosted clips short and compressed, and use lazy loading or click-to-load facades to protect your page speed. Add captions and consider privacy-enhanced embeds, and your videos will be fast, accessible, and a genuine asset to your content.

Tags :
Share :

Related Posts

What are the best WordPress security plugins?

What are the best WordPress security plugins?

The best WordPress security plugins for most sites are Wordfence, Sucuri Security, Solid Security, MalCare, All-In-One Security (AIOS), Patchstack, a

Dive Deeper
What is the difference between posts and pages in WordPress?

What is the difference between posts and pages in WordPress?

The main difference between posts and pages in WordPress is that posts are timely, dated entries that appear in your blog feed, archives, and RSS fee

Dive Deeper
How much does it cost to build a WordPress website?

How much does it cost to build a WordPress website?

Building a WordPress website can cost anywhere from roughly the price of a domain and a year of budget hosting, if you do it yourself with free tools

Dive Deeper