How to Embed an iFrame in WordPress (+ Why It’s Not Working)

iFrame embed options in the WordPress editor

To embed an iframe in WordPress, add a Custom HTML block, click Edit code, paste your <iframe> code into the HTML tab, and click Update. That works for Administrators and Editors. If your iframe disappears on save, your role can’t post raw HTML; if it shows a blank box or “refused to connect,” the source site blocks embedding. Both are covered below.

<iframe
    src="https://example.com/embed-page"
    width="100%"
    height="500"
    title="Example embed"></iframe>

This guide covers the Custom HTML block as it works in WordPress 7.x, when the Embed block is the better choice, the iframe plugin, responsive CSS, and a troubleshooting table for iframes that won’t show up. The role and lazy-loading behavior below was tested on WordPress 7.1.4 in WordPress Playground.


Key Takeaways
  • Paste your <iframe> code into a Custom HTML block (Edit code, HTML tab, Update). For YouTube, Vimeo, Spotify and similar services, the Embed block is simpler.
  • Only Administrators and Editors can save iframe HTML on a single site. Authors and Contributors get it stripped on save, and on multisite only Super Admins keep it.
  • If an iframe shows a blank box or “refused to connect,” the source site blocks framing with X-Frame-Options or CSP frame-ancestors. WordPress can’t override that.
  • Make iframes responsive with width: 100% plus aspect-ratio. WordPress adds loading="lazy" for you when the iframe has width and height.

What is an iFrame?

An iframe (inline frame) is an HTML element that loads another web page inside yours. Common uses: YouTube videos, Google Maps, third-party forms, Calendly widgets, and pages from your own sites.

For popular services (YouTube, Vimeo, Spotify, X, and many more), you don’t need iframe code at all. Paste the regular URL into the Embed block, or on its own line in a paragraph, and WordPress fetches the embed through oEmbed. The Embed block also works for Authors and Contributors, because the iframe is generated when the page renders instead of being saved in the post.

You only need a raw <iframe> when:

  • The service isn’t an oEmbed provider and gives you embed code instead of a link (Google Maps, many form and booking tools).
  • You want control over dimensions, the sandbox or allow attributes, or styling that oEmbed doesn’t give you.
  • You’re embedding a page from your own domain, like a form or a small tool.

Method 1: Embed an iFrame without a plugin (block editor)

The Custom HTML block is the built-in way, and WordPress 7.0 changed how it works: the code now goes into an editing window instead of straight into the block.

  1. Click the + inserter and choose Custom HTML, or type /html in an empty paragraph and press Enter.
  2. Click Edit code on the block toolbar.
  3. Paste your iframe code into the HTML tab. The preview on the right shows what it will look like.
  4. Click Update, then save or publish the post.
Custom HTML block Edit code window in WordPress 7.1 with an iframe in the HTML tab and its live preview
The Custom HTML block’s Edit code window in WordPress 7.1: HTML on the left, live preview on the right

The window also has CSS and JavaScript tabs, but the Custom HTML block documentation notes they only appear for users with the unfiltered_html capability. If you don’t see them, you also can’t save iframes (see the role section below).

A basic iframe embed:

<iframe src="https://example.com/" width="600" height="400" title="Example page"></iframe>

A more complete version, full width, with an accessible title and fullscreen allowed for video:

<iframe
    src="https://www.youtube.com/embed/fd0k_hbXWcQ"
    width="560"
    height="315"
    style="width: 100%; height: auto; aspect-ratio: 16 / 9; border: 0;"
    title="Descriptive title for screen readers"
    allow="fullscreen"></iframe>

On the classic editor, switch to the Text tab and paste the code there. Page builders have their own HTML element (Elementor’s is the HTML widget); paste the iframe into that.

Text tab in the WordPress classic editor for adding iFrame HTML
Text tab in the Classic Editor

Important iframe attributes

  • src: the URL of the embedded page. Use https:// on an HTTPS site, since browsers block HTTP frames on secure pages.
  • width / height: keep both. WordPress uses them to decide whether to add lazy loading, and they reserve space so the page doesn’t jump.
  • loading="lazy": defers the iframe until it’s near the viewport. WordPress has added it automatically to iframes in post content since 5.7, but only when the iframe has src, width and height. Add it yourself for iframes in widgets or templates.
  • title: describes the frame to screen reader users.
  • allow: grants features to the frame, such as allow="fullscreen" for video.
  • sandbox: restricts what the embedded page can do (scripts, forms, popups). Use it for sources you don’t fully trust.
  • frameborder, scrolling, align: obsolete in current HTML. Use CSS like border: 0 instead.

Method 2: Use an iframe plugin (shortcode)

The iframe plugin by webvitalii adds an [iframe] shortcode that accepts the same parameters as the HTML tag. As of this update it’s on version 6.0 (May 2026), has 60,000+ active installs, and is tested up to WordPress 7.0.8, per its wordpress.org listing. It removes on* event attributes such as onload to block script injection.

After installing, use the shortcode in a Shortcode block or anywhere shortcodes work:

[iframe src="https://www.youtube.com/embed/fd0k_hbXWcQ" width="100%" height="500"]

The practical reason to use it: shortcodes aren’t stripped on save, so Authors, Contributors and non-Super-Admins on multisite can embed iframes with it. That is also the trade-off. Anyone who can write posts can then frame any page, so only install it on sites where you trust your writers.

If you need more than a plain frame, Advanced iFrame (40,000+ installs, tested up to 7.1.4, updated November 2026) adds options like resizing the iframe to its content height and hiding parts of a page on the same domain. It’s a much bigger plugin, so start with plain HTML or the simple plugin.

Neither plugin can get around a site that blocks embedding. If the source sends X-Frame-Options or a CSP frame-ancestors rule, nothing on the WordPress side can override it.


How to make an iframe responsive in WordPress

An iframe with fixed pixel dimensions overflows on phones. The modern fix is the CSS aspect-ratio property: let the iframe take the full width and calculate its height from the ratio. Add this through Additional CSS or your child theme’s style.css:

.responsive-iframe {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: 16 / 9;
    border: 0;
}

Then add the class to any iframe:

<iframe
    class="responsive-iframe"
    src="https://www.youtube.com/embed/fd0k_hbXWcQ"
    width="560"
    height="315"
    title="YouTube video"
    allow="fullscreen"></iframe>

Change the ratio to fit the content: 4 / 3 for older video, 1 / 1 for a square map. For an embed that isn’t video, like a form, a ratio rarely fits; use width: 100% and a fixed height instead. To center an iframe narrower than the content column, add max-width and margin-inline: auto to the same rule.

YouTube and other embeds added with the Embed block are already responsive when your theme declares responsive-embeds support. Block themes get it automatically (core adds it for every block theme), so the Twenty Twenty-Five test site reported responsive-embeds support with no extra code. Classic themes have to opt in. Add this to the theme’s functions.php or a code snippets plugin:

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

That support only affects Embed blocks. Iframes pasted into a Custom HTML block still need the CSS class above.


Why your iframe isn’t working

Match what you see to the likely cause, then jump to the matching section:

What you seeLikely causeFix
Gray box with a sad-page icon, or “example.com refused to connect”The source site blocks framing (X-Frame-Options or CSP frame-ancestors)Use the service’s official embed URL or link to it instead
Iframe vanishes when you save or reopen the postYour user role lacks unfiltered_html, so WordPress strips itPost as an Administrator or Editor, or use the Embed block or a shortcode
Iframe stripped for everyone, even AdministratorsDISALLOW_UNFILTERED_HTML is set in wp-config.phpRemove the constant or use the Embed block
Blank frame only on your live HTTPS siteThe src uses http:// (mixed content)Switch the URL to https://
Code won’t save on WordPress.comPlan lacks hosting featuresUse the Embed block or upgrade the plan
“Updating failed” when saving a post with an iframeA firewall rule can flag iframe markup in the requestCheck your firewall or security plugin log and allowlist the request
Common WordPress iframe problems and fixes

The source site blocks embedding (most common)

Many sites send a header telling browsers not to show them inside another site’s frame. The older header is X-Frame-Options: DENY or SAMEORIGIN; the newer one is Content-Security-Policy: frame-ancestors 'self'. When the header is present, Chrome and Brave show a gray box with a sad-page icon (Chrome’s error page reads “example.com refused to connect”), and nothing loads.

A quick header check on November 8, 2026 found X-Frame-Options: SAMEORIGIN on google.com and DENY on facebook.com and github.com. Loading all three in iframes in headless Brave gave three empty frames, while a YouTube /embed/ URL in the same test page played normally.

If you run your own site and want to confirm your headers protect you from being framed by someone else (clickjacking), I built ClickJackTest for that. Paste a URL and it tells you whether X-Frame-Options or CSP is set correctly.

There is no client-side workaround. The fix is the service’s official embed URL if it has one (YouTube’s /embed/ URLs, Google Maps’ Share, then Embed a map option), an Embed block if it’s an oEmbed provider, or a plain link.

Example of a website blocking itself from being loaded in an iframe
Typical blocked-iframe error in the browser

Your user role is stripping iframes on save

WordPress only lets users with the unfiltered_html capability save raw HTML like iframes. Everyone else has their content run through wp_kses on save, and <iframe> isn’t on its allowed list. On WordPress 7.1.4, saving the same Custom HTML block as each default role gave this result:

Role (single site)unfiltered_htmlIframe after save
AdministratorYesKept
EditorYesKept
AuthorNoStripped (empty block)
ContributorNoStripped (empty block)
Tested on WordPress 7.1.4 (WordPress Playground, Twenty Twenty-Five)

On multisite, core maps unfiltered_html to Super Admins only, so even site Administrators and Editors lose iframes on save. Overriding that takes a map_meta_cap filter, which would also let those users add scripts across the network, so treat it as a security decision rather than a quick fix. The safer options are to have a Super Admin add the embed, use the Embed block, or use a shortcode plugin. See WordPress user roles for what each role can do.

One more case: if DISALLOW_UNFILTERED_HTML is set to true in wp-config.php, nobody has unfiltered_html, including Administrators, and every saved iframe is stripped.

HTTPS mixed content

If your site is on HTTPS and the iframe’s src starts with http://, browsers block it as mixed content. Change it to https://. If the source only serves HTTP, it can’t be embedded on an HTTPS site.

You’re on WordPress.com

WordPress.com is stricter than self-hosted WordPress. Its Custom HTML block guide says tags like iframe, script and form require a paid plan with hosting features activated. On other plans, use the Embed block for supported services.

A firewall blocks the save

Iframe markup in a save request can look like a cross-site scripting attempt to a web application firewall, whether that’s a server rule or a security plugin’s firewall. If saving fails only when the post contains an iframe, check the firewall’s blocked-request log and allowlist that request.

The classic editor reformats the iframe

Switching between the Visual and Text tabs in the classic editor can mangle iframe HTML. Stay in the Text tab when working with iframes, or use the Custom HTML block.

Embedding a WordPress site in an iframe elsewhere

Going the other direction, WordPress core sends X-Frame-Options: SAMEORIGIN and Content-Security-Policy: frame-ancestors 'self' on the login page and wp-admin, so those can never be framed by another site. Core doesn’t add those headers to the public front end, but many hosts, CDNs and security plugins do. smartwp.com, for example, returns X-Frame-Options: SAMEORIGIN on its homepage. If you need your front end framed by a specific site, change that header rule (or replace it with a frame-ancestors list naming the allowed site) at the host or plugin level.


Frequently asked questions

How do I embed an iframe in WordPress?

Add a Custom HTML block, click Edit code, paste your <iframe> code into the HTML tab, and click Update. On the classic editor, paste it in the Text tab. For YouTube and other oEmbed services, paste the URL into an Embed block instead.

Why isn’t my iframe working in WordPress?

Usually the source site blocks framing with an X-Frame-Options or Content-Security-Policy frame-ancestors header, which shows up as a blank frame or “refused to connect.” If the iframe disappears after saving, your user role lacks unfiltered_html. Less often it’s an http:// URL on an HTTPS site.

Why does my iframe disappear when I save the post?

Your account doesn’t have the unfiltered_html capability, so WordPress removes the iframe with wp_kses when you save. On a single site, Authors and Contributors lack it; on multisite, everyone except Super Admins does. Use the Embed block, a shortcode plugin, or have an Administrator (Super Admin on multisite) add it.

Custom HTML block iframe and unfiltered_html: what does the documentation say?

The WordPress.org Custom HTML block documentation says that if a user lacks unfiltered_html (for example, a Contributor), WordPress sanitizes the block with wp_kses(), stripping tags such as script and iframe, and hides the CSS and JavaScript panels.

Does wp_kses_post allow iframe tags?

No. The default allowed list for post content doesn’t include iframe, so wp_kses_post() strips it (confirmed on WordPress 7.1.4). Developers who need iframes in filtered content can extend the list with the wp_kses_allowed_html filter, but that opens the same risk unfiltered_html protects against.

What does wp_oembed_get return?

wp_oembed_get( $url ) returns the provider’s embed HTML as a string, which for YouTube is an iframe, or false if the URL isn’t a supported provider or the request fails.

What is the best iframe plugin for WordPress?

For a simple shortcode, the iframe plugin by webvitalii (60,000+ installs, updated May 2026). For auto-height and hiding parts of a same-domain page, Advanced iFrame (40,000+ installs, updated November 2026). Most sites don’t need either: the Custom HTML block and the Embed block cover the common cases.

Can I embed any website in a WordPress iframe?

No. Sites that send X-Frame-Options or a CSP frame-ancestors rule can’t be framed, and that includes Google, Facebook and GitHub. You can embed sites that allow it, usually through an embed URL or widget they provide (YouTube, Vimeo, Calendly, Google Maps).

How do I make an iframe responsive in WordPress?

Give the iframe width: 100%, height: auto and an aspect-ratio such as 16 / 9 with CSS, as shown in the responsive section above. Embed blocks are responsive on their own when the theme supports responsive-embeds, which every block theme does by default.

Is it safe to embed iframes from other sites?

From trusted sources like YouTube, Google Maps and Calendly, yes. For anything else, add the sandbox attribute to limit what the embedded page can do, and only embed sources you trust.


Bottom line

For most embeds, use the Embed block if the service supports it, and a Custom HTML block for everything else. Keep width and height on the iframe, add a title, and use the aspect-ratio CSS for video.

If the iframe won’t load, check the troubleshooting table: a blank frame means the source site blocks embedding, and an iframe that vanishes on save means your role can’t post raw HTML.

Picture of Andy Feliciotti

Andy Feliciotti

Andy has been a full time WordPress developer for over 15 years. Through his years of experience has built 100s of sites and learned plenty of tricks along the way. Found this article helpful? Buy Me A Coffee

40 Responses

  1. Great video! Very helpful in helping me get a Tableau map installed on a site I’m developing. Any advice for adding a border or close button? I’m interested in integrating with a Elementors’ native ‘popup’ functionality but haven’t quite determined how to best accomplish what you have here.

  2. HI, I am trying to embed things )not always videos into a masterstudy lesson. CAn you show how this is done please?

  3. Thank you for the tip, how do i make sure the iframe does not get longer than the page so i get double scroolbars?

  4. Andy, I have been requested to add a custom widget to a third party portal on our website. I have been attempting this but have been unsuccessful. Any tips for how to apply this? We use BeaverBuilder for front end content.

    1. What is the issue happening? if your site is https and the site you are putting in an iframe is http it will not load. Additionally in WordPress you can use the text widget and select html to use html to embed it. Also if you are trying to do it in beaverbuilder there should be a raw html block you can use to embed an iframe.

      If it’s not working most likely it’s security related. If it’s a WordPress Multisite setup you have to have unfiltered html enabled for it to work.

      The easiest solution is probably to just use the plugin noted above.

  5. Hi,
    Now not work plugin OPEN FRAME in browsers, and not work function Open frame in new tab, and cannot be read iframe on webpage. Is there a solution?

    1. Hey Ron! Since it’s just an image have you tried doing just an image HTML tag?

      <img src="https://docs.google.com/spreadsheets/d/e/2PACX-1vQpMUgFOt5C3S3sLEFLYzQO5ekyZttTvlpKy7SYVFRpI4o0_IbgA5iB9qPO89is1Vlf8g6q1glf0NMf/pubchart?oid=570910300&format=image">

      Just tested this and the image will scale properly on your site using this method.

      1. Andy,
        Thank you for the fast reply, a do appreciate ty this much
        Wow, how simple is that 🙂 .
        Sometimes one turnes into a wrong way .
        Many Thanks

        Ron

  6. Thank you Andy for the video , I'm just wondering if i can embed a part of a page on my website, not the whole page ( a forum for example into my page )
    Is this possible?

  7. hey, Andy, can u do this for google drive embedded video, also I want to disable the top right corner pop-out button

  8. Thank YOU Andy,

    Your post is short, to the point, and FILLED with the info I needed (no hunting through loads of content… pheeew!) as well as a video for the visual learners, like me 🙂 .

    Thanks again,
    Trish

  9. Hey Andy, I have a bunch of videos on my website already. All embedded by just copy-pasting the embed code from YouTube. Your process requires me to put the div class around every video to work. That would unfortunately take a lot of time. Is there any way to make all the videos I already have become responsive without using any plugin?
    Thanks.

  10. It didn’t work. It says “Unable to communicate back with site to check for fatal errors, so the PHP change was reverted. You will need to upload your PHP file change by some other means, such as by using SFTP.”

    What do I do now?

  11. Can you also embed powerpoint show files? I have powerpoint games that I want to embed on my website. Some buttons on the powerpoint dont work with some plugins.

    1. I’m not too familiar with embedding a powerpoint, it may be a limitation of the web browser making the game not work. If you are looking to distribute games via the browser I’d recommend using Javascript and HTML.

  12. This is so helpful! Any chance you have a full list of why a site might not be “embeddable”? For example, it seems like if a site has iframes, it can’t be embedded in an iframe?

  13. Hi Andy, great article! Any chance you can provide some guidance on how to fix the scroll within a scroll in a window? It makes very difficult, especially on mobile devices. Not sure if it’s a responsiveness issue or something else? Here is a page as an example: https://www.moderndiamondco.com/jewelry/

    Thanks!

  14. Hey Andy.
    Thank you so much for your article.. it helped so much..
    quenstion.. it you have the time..
    is it posible to ad a link so when you click the iframe you go to the ad website?
    if posible how would you code it?

    thank you again!
    kind regards Marlene.

  15. I tried this responsive code on my wordpress and nothing really happened. Only using width=100% makes the video embeds look at all decent. I have also tried similar codes from others and none of them worked also. Embedding videos without iframe would look the best but I can’t get any video views to count on youtube with those, so I probably have to stick with unresponsive embeds?

  16. Hi I’m trying to iframe my teespring website in my wordpress. I have it where it shows up in preview but won’t show up on the actual public site after I update. Cn you please help? here is the code I’m using to embed (iframe) my Teespring website into Wordpress.

  17. HI ANDY
    the height in my video is non “responsive”

    the width changes when i resize screen but height doesn’t change so content isgetting cropped

  18. I tried all of this with an interactive video but still does not have the correct ratio. The video opens too big and I can’t rezise it.

  19. Thank you for your blog post.
    I am facing a similar issue on my website for embedding geogebra applet using iframe. I tried your suggested method, but unfortunately it did’t work.
    Here is my embedding code

    It always leaves a white space in the right side of applet for desktop and in the bottom for mobile version. https://physicsentrance.com/jacobian/
    I am using elementor page builder in wordpress.
    Thank you.

    Please help me to solve this issue.

  20. hey, Andy, can u do this for google drive embedded video, also I want to disable the top right corner pop-out button

    1. I’m not sure if Google Drive videos will embed, that being said you likely can’t modify what’s inside an iframe. Google Drive might have a built in oEmbed though that might be a better solution than an iframe.

Leave a Reply

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

WordPress Tips Monthly
Get the latest from SmartWP to your inbox.