There are many uses on the web for embedding iFrames into your website. This could include videos, images, or even other websites. You can even use iframes on your site to save storage space on your site by embedding content from another server.
Here we’ll show you how to embed an iframe in WordPress with and without a plugin. Additionally I’ve included how to make YouTube embeds responsive using CSS.
What is an iFrame?
iFrames have been part of the html since its creation. iFrames allow websites to embed content from other websites.
Many sites have new security policies that do not allow them to appear in iFrames in favor of oEmbeds which are natively supported by WordPress. But for sites that do not offer oEmbed support an iFrame can come in handy.
How to embed iFrame in WordPress Without Plugin
The most basic way to add an iFrame in WordPress is to use HTML. This can be done in the “Text” tab of the classic editor.
If you’re using Gutenberg you’ll have to add a Custom HTML block.
Here is example HTML to put Bing.com into an iFrame. You can replace the Bing URL with whichever site you would like to embed with an iFrame.
- Src – The source of the iFrame, this is a URL. If your site has SSL you need to ensure all iFrames start with https://.
- Width/Height – Width and height are pixel values defining the size of your iFrame.
- Frameborder – Setting frameborder=”1″ will show a small border around the edges of the iFrame. frameborder=”0″ will hide the edges of the iFrame making it flush with your page (good video videos).
- Scrolling – Whether or not you want scrollbars in your iFrame, values include “yes”, “no”, or “auto”.
- Align – Set the default alignment of the iFrame, values include “left” “right” “top” “middle” “bottom”.
This is not the optimal solution since a lot of hosts will block iframes due to security concerns. That is why it is optimal to use our next method of a WordPress plugin.
Additionally, it’s important to note that not all sites will work. For example, the site you’re embedding could block itself from being included in an iframe. If your site has SSL also (https:// before your URL) embedding a non-https page via an iframe will not work since browsers will block non-https assets.
If you’re embedding an iframe with a page builder like Elementor you typically can just use their “html” block with the iframe code above.
WordPress iFrame Embed Plugin
The best way to embed a WordPress iFrame is to use a plugin. The iFrame plugin on the WordPress.org repository will give you the best results. This plugin offers the same features as embedding an iFrame but is generated via a simple to use shortcode.
Below is an example of how to use the shortcode for the iFrame plugin.
If you are new to shortcodes all you have to do is add it into your editor after the plugins installed.
Similar limitations will also apply regardless if you’re using a plugin or now. If the embed doesn’t work most likely the site you’re embedding blocks it or you are using https and including a non-https page.
Make YouTube Embeds Responsive in WordPress
If you’re including a YouTube video on your page you may notice the aspect ratio isn’t correct when resizing the page for responsive web design. This is because iFrames have a fixed height, you can make your embeds responsive by using the CSS below.
After adding this CSS to your site you can wrap any video with a div like this <div class=”responsive-embed-container embed-responsive-16by9″> which will give it the appropriate class to become responsive. You can see a full example of how an embed would work using this CSS below.
Additionally you can add this code snippet to your functions.php to automatically wrap all YouTube oEmbed with the proper div.
You can also use a plugin like Simple YouTube responsive if you’re not familiar with CSS, HTML or PHP.
We hope these tips help you embed WordPress iframes and allow you to share content across domains. Embedding an iFrame in WordPress can be easily accomplished with or without a plugin. By following the simple steps outlined in this blog post, you can seamlessly integrate external content into your website while maintaining a user-friendly experience for your visitors.
Whether you choose to use a plugin or opt for manual coding, make sure to test the iFrame thoroughly to ensure it displays correctly across different devices and browsers.
It’s important to note that if you’re sharing content from popular sites like YouTube or Twitter you can just paste the URL in your WordPress editor. This will use an oEmbed to automatically embed the content.