Embeds
This is a library of methods for embedding various media into WordPress or hand-coded websites, with an emphasis on responsive design. Updated to include the new aspect-ratio CSS property… no more hacky padding!
In the WordPress ecosystem, some plug-ins provide functionality, but over-reliance on plug-ins can lead to trouble. With a little code, you can avoid that — and get more fine-grained control over your work.
Images
Single Flickr image
WordPress, responsive
Most modern WordPress themes will create a responsive image for you that will change size for specific device display.
- Select a Flickr image
- Select Share photo icon: the curved arrow at the lower right of image
- Select Share and copy the URL
- Paste on its own line in a post to automatically create a responsive Flickr embed
Code, fixed size
- Select a Flickr image
- Select Share photo icon
- Select Embed, choose size, and copy code
- Paste into html for your page
- Customize
width="XXX"
andheight="YYY"
if desired:
<a data-flickr-embed="true" data-context="true" href="https://www.flickr.com/photos/williamcromar/52805942069/in/album-72177720315295622/" title="Kirkton of Aboyne"><img src="https://live.staticflickr.com/65535/52805942069_1468e103d1_c.jpg" width="800" height="601" alt="Kirkton of Aboyne"/></a>
<!--Delete the scrjpt:-->
<scrjpt async src="//embedr.flickr.com/assets/client-code.js" charset="utf-8"></scrjpt>
** letter i in script changed to j to disable response
Code, responsive
- Select a Flickr image
- Select Share photo icon
- Select Embed, choose large or original size, and copy code
- Delete
width
andheight
parameters, and delete the entirescript
- Create the following CSS in the head of the html:
<style>
.container {
position: relative;
aspect-ratio: 3/2;
width: 100%;
height:100%;
}
.imgscale {
position:absolute;
top:0;
left:0;
width:100%;
height:100%;
}
</style>
- Create a new
<div>
around the<img>
, and apply classcontainer
to the<div>
and classimgscale
to<img>
:
<a data-flickr-embed="true" data-context="true" href="https://www.flickr.com/photos/williamcromar/52805942069/in/album-72177720315295622/" title="Kirkton of Aboyne">
<div class="container">
<img class="imgscale" src="https://live.staticflickr.com/65535/52805942069_1468e103d1_c.jpg" width="800" height="601" alt="Kirkton of Aboyne"/></a>
</div>
- This breaks the link back to Flickr, but their terms of service require a link. To fix, delete
data-flickr-embed="true"
and addtarget="_blank"
<a href="https://www.flickr.com/photos/williamcromar/28052123767/in/album-72157695032282922/" title="31402e1" target="_blank">
<div class="container">
<img class="imgscale" src="https://live.staticflickr.com/875/28052123767_8c056d7e09_o.jpg" alt="31402e1"/>
</div>
</a>
Flickr slideshow
Trickier than it should be! WordPress plug-ins exist but are not optimal. Coding helper sites exist, such as flickrembed.com. However, you’re dependent upon their self-hosted scripts, and if they go down, your gallery goes with it. Better just to download and use your own scripts if you have a server: Unite Gallery is a great one (flickerembed.com is built with it).
But if you just want to embed a darn slideshow and be done with it here are some solutions without cost or technical weeds.
WordPress, pseudo-responsive
- Open a Flickr album in a browser window
- Copy the URL for the album
- Paste on a new line in a post to automatically create a “responsive-ish” Flickr embed
Resize the browser window on the desktop and you can see the liability of this solution: the embed frame is responsive to a degree, but the image is not, and this can hide the controls. Refreshing the browser window can reset the image size, but this a is pretty counterintuitive UX. Use it with caution.
Code, fixed size
- Open Flickr album
- Select the Share album icon on the album page: the curved arrow under the album title
- Select Embed, select a size, and copy the code
- Paste into HTML for your page
- Customize
width="XXX"
andheight="YYY"
if desired:
<a data-flickr-embed="true" href="https://www.flickr.com/photos/williamcromar/albums/72157695032282922" title="3dModelingElements">
<img src="https://live.staticflickr.com/1802/42921015881_53f3fcea37_z.jpg" width="270" height="180" alt="3dModelingElements"/>
</a>
<!--Delete the scrjpt:-->
<scrjpt async src="//embedr.flickr.com/assets/client-code.js" charset="utf-8"></scrjpt>
** letter i in script changed to j to disable response
Code, responsive
- Select a Flickr album.
- Note and copy the unique identifier for the album – the numbers at the end of the URL as in this example:
https://www.flickr.com/photos/williamcromar/albums/72157695032282922
- Copy and paste the number only into this iframe code (between
photosets/
and the closing"
in thesrc
:
<iframe style="width: 100%; height: auto; aspect-ratio: 16/9;" src="https://embedr.flickr.com/photosets/72157695032282922" scrolling="no"></iframe>
Though this is a disarmingly simple solution, it may ultimately be hacky. Flickr has been pushed around by changes in technology and ownership so who knows how long embedr.flickr.com will work…
GIF or APNG, static or animated
WordPress, responsive
- Can host directly in Media Library, just insert as you would any other image — but using Thumbnail or Medium will disable any animation
- Themes often take care of image responsiveness automatically. If not use the code solution below.
Code, responsive
- Place
<img>
in your HTML then add inlinestyle
forwidth
,height
, andaspect-ratio
properties as per example:
<img style="width: 100%; height: auto; aspect-ratio: 1/1;" src="https://williamcromar.com/newmediawiki/wp-content/uploads/2023/07/Wind_turbine.png" alt="wind">
- If limiting image size is desired to avoid over-scaling in a responsive context, use the
max-width
property:
<img style="width: 100%; max-width: 300; height: auto; aspect-ratio: 1/1;" src="https://williamcromar.com/newmediawiki/wp-content/uploads/2023/07/Wind_turbine.png" alt="wind">
Inline style can of course be added as a class to the html head or a css file if flexibility of use is desired.
SVG, static, or animated
WordPress, responsive
- Because SVG is a markup language like HTML, an SVG “file” is just code. WordPress Media Library will not host an SVG without a plug-in. Find a hosting solution for your image and use the code below.
Code, responsive
- Place the
iframe
code below in your HTML - Replace the
src
with the URL of your file - Change the
aspect-ratio
property to match that of your image.
<iframe style="width: 100%; height: auto; aspect-ratio: 3/2.01;" src="https://upload.wikimedia.org/wikipedia/commons/0/05/Moire_Circles.svg" scrolling="no" frameborder="0"></iframe>
Why the “2.01” in the aspect ratio?
The ratio of this vector image is 3/2, but pixelation at certain scales creates a cutoff of the image edge. Making one variable slightly larger avoids a tangent with the image, creating clean pixelation at any scale.
Video
Video embeds with minimalist chrome
In the context of a video embed, the term “chrome” refers to the fixed design aspect of the player. Some video hosts, such as Vimeo, allow a great deal of control over the amount of chrome you allow. Others, like YouTube, started out that way but their API is getting stricter by the day. A self-hosted video give you the most control but also uses a lot of your server resources.
Self-hosted, responsive
- Upload a video to a personal server
- Place the URL for the video in the
src
of a<video>
tag - Place the
<video>
tag inside a<div>
- Style the div and video as you see in the code below
- Include a variety of video parameters, such as
no-controls
,autoplay
,muted
, orloop
, to give you or the client a range of control over the look and play - The inline styles can be changed to classes in the head of the HTML if desired.
<div style="position: relative; aspect-ratio: 16/9; width: 100%; height:100%;">
<video style="position:absolute; top:0; left:0; width:100%; height:100%;" no-controls autoplay muted loop src="https://williamcromar.com/video/glenco21.mp4">
</video>
Your browser does not support the video element
</div>
Autoplay in audio and video should be used sparingly. It’s good for creating an active hero image, for example.
WordPress using Vimeo or YouTube URL
- Copy the video URL and paste it into the post.
- Most modern WordPress themes will automatically create a responsive video this way — if not, try a code-based solution.
Note the UI chrome in this embed from Vimeo, where Settings control the parameters — not the code — so you can get a minimalist solution this way.
For YouTube, not so much — you have to use the YouTube API to set parameters in code. YouTube allows much less control than Vimeo here.
But, note the less-than-optimal vertical spacing: the actual video height in pixels persists! You have to get rid of that in a code-based solution.
Code using generated iframe, responsive
- Go to the video at the hosting site and hit the Share button, then find an embed generator
- At YouTube, you’ll have to add CSS the same way we did for a Flickr single image using the responsive code above.
- At Vimeo, shown here, you can select a responsive option in the embed generator, then copy the code and paste it into your HTML:
<div style="padding:56.25% 0 0 0;position:relative;">
<iframe src="https://player.vimeo.com/video/111212129?h=d4ab8d73e3&title=0&byline=0&portrait=0" style="position:absolute; top:0; left:0; width:100%; height:100%;" frameborder="0" allow="fullscreen; picture-in-picture" allowfullscreen></iframe>
</div>
<scrjpt src="https://player.vimeo.com/api/player.js">
** letter i in script changed to j to disable response
Note this gets rid of the persistent gap at the top and bottom!
Audio
Self-hosted sound file
WordPress
- Easy: Host file in Media Library or a personal server, use Add Media button (classic editor) or Audio block (block editor) to insert.
Code, responsive width
- Simple coding task using the
<audio>
element to auto-generate a player control - Add inline
width
style in the tag for a responsive width:
<audio controls style="width: 100%;">
<source src="https://williamcromar.com/newmediawiki/wp-content/uploads/2023/07/mona_lisa_harassment4.mp3" type="audio/mpeg">
Your browser does not support the audio element
</audio>
Hosted music or podcast
WordPress, Soundcloud hosted
- Copy the URL and paste it into a post.
- Most modern WordPress themes will automatically create a responsive embed this way — if not, try a code-based solution.
Code, Soundcloud hosted, minimal chrome
- Use SoundCloud Share icon to generate, copy, and paste iframe into your html
- Customize width to generate a responsive embed:
<iframe width="100%" height="166" scrolling="no" frameborder="no" allow="autoplay" src="https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/176086400&color=%23847c74&auto_play=false&hide_related=false&show_comments=true&show_user=true&show_reposts=false&show_teaser=true"></iframe>
<div style="font-size: 10px; color: #cccccc; line-break: anywhere; word-break: normal;overflow: hidden;white-space: nowrap;text-overflow: ellipsis; font-family: Interstate,Lucida Grande,Lucida Sans Unicode,Lucida Sans,Garuda,Verdana,Tahoma,sans-serif;font-weight: 100;">
<a href="https://soundcloud.com/williamcromar" title="williamcromar" target="_blank" style="color: #cccccc; text-decoration: none;">williamcromar</a>
<a href="https://soundcloud.com/williamcromar/tangent-dumbo-loop-for-the-sound-of-flyspec" title="Tangent Dumbo Loop for the sound of flyspec" target="_blank" style="color: #cccccc; text-decoration: none;">Tangent Dumbo Loop for the sound of flyspec</a>
</div>
Slide decks
Google Slides
Google Slides, fixed size (pseudo-responsive)
- For WordPress, use the code below in the Text tab (classic editor) or Custom HTML block (block editor)
- In Slides browser menu, select File > Publish to Web, and in the dialog, choose Embed
- Customize
width
andheight
if desired, and if no auto-advance is wanted, delete&delayms=3000
:
<iframe src="https://docs.google.com/presentation/d/e/2PACX-1vS1913cOh-KjNaoukEuyLatTn8hthiNT3ucVtbEWJXYnoMy622fwHbRCeuhXYQK60D8gQ2vobTRIuRu/embed?start=false&loop=false&delayms=3000" frameborder="0" width="960" height="569" allowfullscreen="true" mozallowfullscreen="true" webkitallowfullscreen="true"></iframe>
Note: in our sample, we changed the default width and height values to 400 pixels each. The width will change if the width of the div holding the embed is smaller than 400 — but it will never get wider than 400 if the div is larger.
Google Slides, responsive, looping, no controls
- In WordPress, use code below in Text tab (classic editor) or Custom HTML block (block editor)
- In Slides browser menu, select File > Publish to Web, and in the dialog, choose Embed
- Add a variety of functions to the generated iframe code, such as auto-start (add
start=false
), looping (addloop=true
), and removing controls and branding (addrm=minimal
) in the basic iframe code above: don’t forget the&
between each function - Customize the auto-advance
delayms=
to desired time in milliseconds:1000
= 1 second
<iframe src="https://docs.google.com/presentation/d/e/2PACX-1vS1913cOh-KjNaoukEuyLatTn8hthiNT3ucVtbEWJXYnoMy622fwHbRCeuhXYQK60D8gQ2vobTRIuRu/embed?start=true&loop=true&rm=minimal&delayms=5000" frameborder="0" width="960" height="569" allowfullscreen="true" mozallowfullscreen="true" webkitallowfullscreen="true"></iframe>
- To make responsive, first remove the
width
,height
, andfullscreen
parameters from the iframe - Add the following CSS to your html (you can add as classes in the head as shown or style inline):
<style>
.container-slide {
position: relative;
aspect-ratio: 16 / 9;
overflow: hidden;
}
.responsive-slide {
border: 0;
position: absolute;
top: 0;
left: 2px;
width: 100%;
height: 100%;
}
</style>
- Wrap the iframe inside a
<div>
with thecontainer-slide
class applied, and assign theresponsive-slide
class to the iframe
<div class="container-slide">
<iframe class="responsive-slide" src="https://docs.google.com/presentation/d/e/2PACX-1vS1913cOh-KjNaoukEuyLatTn8hthiNT3ucVtbEWJXYnoMy622fwHbRCeuhXYQK60D8gQ2vobTRIuRu/embed?start=true&loop=true&rm=minimal&delayms=5000"></iframe>
</div>
Why left: 2px;
in the code?
Applying the 16/9 aspect ratio is easy, but the browser must render in whole numbers of pixels. This can lead to an unsightly black edge on the right side. Nudging the embed with a “pixel shim” eliminates that! Mileage may vary: tweak the value as needed in your context.
Powerpoint
You may not be able to view this if you don’t go to my school, even though I’ve “shared” it with “anyone”
Powerpoint, fixed size
The best method for embedding a Powerpoint? Don’t bother. Use Google Slides. In the first embed, you may be required to sign in, even if “anyone” has been correctly set in share settings. All the advice (2017) and workarounds (2021) in the world won’t solve this issue if your IT administrators restrict Office file sharing. Powerpoint Online is a walled garden.
This cost me precious Google Drive storage! You’re welcome.
If you must insist on embedding a Powerpoint, download the file, then upload it to Google Drive to share as per the instructions for embedding Google Slides. Some functionality may get lost, and it costs storage in Google Drive, whereas a native Google Slides file does not.
Just creating a slide deck in Google Slides is the better option!
Adobe Express
Adobe Express, fixed size
- In WordPress, use code below in Text tab (classic editor) or Custom HTML block (block editor)
- Copy and paste embed code available at the Express site into your html
- Customize
width
andheight
if desired:
<iframe src="https://express.adobe.com/video/qrxyUaupggl1y/embed" width="270" height="152" frameborder="0" allowfullscreen></iframe>
This player can be made responsive by using the CSS technique seen at Google Slides Responsive, looping, no controls above.
3D models and interactives
Models
p3D hosted, pseudo-responsive
- In WordPress, p3D provides short-code options but they require a plug-in, so just use code below in Text tab (classic editor) or Custom HTML block (block editor)
- At your p3D model, open the dialog found at the Share icon, select Website/Blog, and check <iframe> Embed Code
- Customize
width
andheight
if desired:
<iframe allowfullscreen width="100%" height="270" loading="lazy" frameborder="0" src="https://p3d.in/e/fKidL+spin"></iframe>
Setting the width
at 100% makes the embed pseudo-responsive. Make it fully responsive by using the CSS technique seen at Google Slides Responsive, looping, no controls above.
Fusion 360, pseudo-responsive, scaled UI
- In WordPress, use code below in Text tab (classic editor) or Custom HTML block (block editor)
- Open the Fusion 360 model available online, find the Share icon, then copy and paste embed into your html
- Change
width
to 100% for pseudo-responsiveness, and tweak theheight
parameter as desired:
<iframe src="https://myhub.autodesk360.com/ue2d86514/shares/public/SH919a0QTf3c32634dcf9517b3555d85ea40?mode=embed" width="100%" height="400" allowfullscreen="true" webkitallowfullscreen="true" mozallowfullscreen="true" frameborder="0">
<p>Your browser does not support iframes.</p>
</iframe>
I really hate Autodesk’s embed. You can’t help but notice their terrible, arrogantly out-of-scale intrusive user interface!
I created a hacky but simple workaround below, which you can see live at CodePen. Add all the code highlighted below to the basic iframe, and tweak width, height, and padding-top parameters as needed in your coding context:
<style>
.container-autodesk {
width: 200%;
display: inline-block;
position: relative;
overflow: hidden;
}
.auto-scale-autodesk {
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
}
.auto-scale-autodesk>iframe {
width: 100%;
height: 100%;
}
</style>
<div class="container-autodesk">
<div class="auto-scale-autodesk">
<iframe src="https://myhub.autodesk360.com/ue2d86514/shares/public/SH919a0QTf3c32634dcf9517b3555d85ea40?mode=embed" width="100%" height="400" allowfullscreen="true" webkitallowfullscreen="true" mozallowfullscreen="true" frameborder="0"
style="width:200%; height:800px;
-moz-transform: scale(0.5, 0.5);
-webkit-transform: scale(0.5, 0.5);
-o-transform: scale(0.5, 0.5);
-ms-transform: scale(0.5, 0.5);
transform: scale(0.5, 0.5);
-moz-transform-origin: top left;
-webkit-transform-origin: top left;
-o-transform-origin: top left;
-ms-transform-origin: top left;
transform-origin: top left;
overflow: hidden;">
<p>Your browser does not support iframes.</p>
</iframe>
</div>
<div style="padding-top: 400px;">
</div>
</div>
Interactives
ThreeJS interactive
- In WordPress, use code below in Text tab (classic editor) or Custom HTML block (block editor)
- The ThreeJS interactive object is a website hosted at a personal server
- Code an
<iframe>
in this manner, using awidth
of 100% for pseudo-responsiveness:
<iframe src="https://williamcromar.com/meme_n_to_ma_ga_m_or_i/" style="border: 0px #ffffff none;" name="ambassador-skull" scrolling="no" frameborder="0" height="400px" width="100%" allowfullscreen></iframe>
Make this iframe fully responsive if desired by using the aspect-ratio
property as seen in the next example, but it’s usually not necessary for this kind of interactive.
HTML5 animated interactive
- In WordPress, use code below in Text tab (classic editor) or Custom HTML block (block editor)
- The HTML5 interactive object is a website hosted at a personal server
- Code an
<iframe>
in this manner, using theaspect-ratio
property as seen in the inline style applied below:
<iframe style="aspect-ratio: 3 / 2; height: auto; width: 100%;" src="https://williamcromar.com/student_samples/animate_alpha/pro3.html" style="border:0px #ffffff none;" name="animate" scrolling="no" frameborder="0" allowfullscreen></iframe>
HTML5 interactives like this often use a canvas
property with a defined aspect ratio, so a fully responsive solution is almost always desirable. This one has a 3/2 ratio: tweak this to fit your context.
Publications
Yumpu hosted flipbook
- In WordPress, use code below in Text tab (classic editor) or Custom HTML block (block editor)
- At the Yumpu page for the hosted PDF publication, find the Embed icon and generate a fixed or responsive <iframe> to copy and paste into html:
<style>
.embed-container {
position: relative;
aspect-ratio: 16 / 9;
height: 0;
overflow: hidden;
max-width: 100%;
}
.embed-container iframe, .embed-container object, .embed-container embed {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
</style>
<div class="embed-container" data-page-width="500" data-page-height="500" id"ypembedcontainer">
<iframe src="https://www.yumpu.com/la/embed/view/x3nCQaR4L2bKkATF" frameborder="0" allowfullscreen="true" allowtransparency="true"></iframe>
<br>
<a href="https://www.yumpu.com/la/document/view/63830940/2018-cromar-tension-portfolio-pages" title="2018_cromar_tension_portfolio_pages" target="_blank">2018_cromar_tension_portfolio_pages</a>
</div>
<scrjpt src="https://players.yumpu.com/modules/embed/yp_r_iframe.js" >
</scrjpt>
** letter i in script changed to j to disable response
The auto-generated code from Yumpu comes with some issues: attributes come with single quotes where they should be double, responsiveness is not created with the aspect-ratio
property, etc. The code you see above has been cleaned up to reflect better form, and it’s advisable to follow that practice!
E-publishers like Yumpu or Issuu have a freemium-level account that generates a popup ad (which you can see here). At Yumpu, the upgrade to avoid this is free for 30 days, then a whopping $20/mo as of this writing. The ad disappears after a few clicks. So if using in a presentation, click on pages beforehand until the ad clears.
WordPress hosted document
- Upload a PDF file to the Media Library and then link to it in your post or page by using a File block in the block editor
Cloud documents
Google Docs, Sheets, or Forms
- Follow instructions above for Google Slides
☠️
Word, Excel, or Microsoft Forms
For the same reasons cited above for Powerpoint, don’t waste your time. Use Google Docs, Sheets, or Forms.