- PHP 83.2%
- CSS 8.7%
- JavaScript 8.1%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| assets | ||
| docs/images | ||
| tests | ||
| autoembed.php | ||
| autoembed.yaml | ||
| blueprints.yaml | ||
| CHANGELOG.md | ||
| LICENSE | ||
| README.md | ||
Auto Embed
Paste a plain YouTube, Vimeo, X (Twitter), or Instagram link on its own line in a page's Markdown, and this plugin turns it into a live embedded player/post — no shortcode, no copy-pasting iframe/embed code by hand.
Check out this talk:
https://www.youtube.com/watch?v=dQw4w9WgXcQ
More thoughts on this over on X:
https://x.com/someuser/status/1234567890123456789
Both links above render as full embeds on the live page.
Big Buck Bunny © Blender Foundation, CC BY 3.0. A link that sits inside a sentence, or on the same line as other text, is left completely alone — it stays a normal clickable link. Only a URL that is the sole content of its own paragraph gets converted.
Supported sites
- YouTube —
youtube.com/watch?v=...(thevparameter can be anywhere in the query),youtu.be/...,youtube.com/shorts/...,/embed/...and/live/..., on any YouTube host (www.,m., ...) - Vimeo —
vimeo.com/... - X / Twitter — any
.../status/...link onx.comortwitter.com - Instagram —
instagram.com/p/...,/reel/...,/tv/...
Each one can be switched on/off independently in the plugin settings.
The provider is decided by the link's host name, so https://example.com/youtube.com/watch?v=...
or a netflix.com/.../status/... link (which merely ends in "x.com") stays an ordinary link.
How it works
No API keys, no oEmbed calls, no rate limits:
-
YouTube shows the video's picture with a play button, and YouTube's player (about 1 MB of scripts) only loads when someone presses it; a small script from the plugin swaps it in, playing. The picture is copied to your site the first time it's asked for (into
images/autoembed/youtube/, then served as a plain file), so the page contacts YouTube only when someone presses play. Only videos the site embeds are fetched (the list is inuser/data/autoembed/), so a made-up address can't make the server download anything. Without JavaScript the button is a link to the player. Turn Load YouTube's player on demand off to embed the player straight away. -
Vimeo (and YouTube, with on demand off) becomes a responsive
<iframe>player, wrapped in a 16:9 container that scales with your page width (this can be turned off in settings if your theme already handles responsive iframes). -
X/Twitter and Instagram become the platforms' own official
<blockquote>embed markup, and the plugin automatically loads their widget script (platform.twitter.com/widgets.js/instagram.com/embed.js) on any page that actually shows one — never on pages that don't. That includes a blog listing whose posts' summaries show an embed. A small script from the plugin checks the finished page first, so if your theme leaves embeds out of the listing, X and Instagram aren't contacted. The blockquote holds a "View this post on X" (or Instagram) link, which is what visitors see if the widget can't load:
Because it hooks into onPageContentProcessed, the conversion happens once
per page (as part of Grav's normal content caching), not on every request.
Install
git clone forgejo@code.hall.me.uk:david/autoembed.git user/plugins/autoembed
Or copy this whole folder into your Grav install so the folder structure looks like:
your-site/
user/
plugins/
autoembed/
autoembed.php
autoembed.yaml
blueprints.yaml
assets/
autoembed.css
Then enable it either in user/config/plugins/autoembed.yaml
(enabled: true, which is the default) or from Admin2's Plugins list.
No further setup needed — it works immediately for any page whose Markdown is processed by Grav.
Configuration
Copy user/plugins/autoembed/autoembed.yaml to
user/config/plugins/autoembed.yaml to override the defaults, or use the
Admin panel form:
| Option | Default | Description |
|---|---|---|
enabled |
true |
Master on/off switch |
responsive |
true |
Wrap YouTube/Vimeo iframes in a scaling 16:9 container |
youtube.enabled |
true |
Enable YouTube embeds |
youtube.privacy_enhanced |
true |
Serve the YouTube player from youtube-nocookie.com |
youtube.on_demand |
true |
Show the video's picture and load the player when play is pressed |
vimeo.enabled |
true |
Enable Vimeo embeds |
twitter.enabled |
true |
Enable X/Twitter embeds |
instagram.enabled |
true |
Enable Instagram embeds |
Notes and limitations
- This only runs on the live/front-end render, not inside the Admin page editor's preview pane, so you won't see the embed while editing — only once you view the actual page.
- X and Instagram embeds need JavaScript and a live internet connection for the visitor's browser to render (they load the provider's widget script, which then fills in the blockquote). If a post is deleted or made private, the blockquote will show a plain "View on X/Instagram" fallback link instead, same as on any other site using these official widgets.
- Cookies/privacy: the X and Instagram widget scripts are third-party scripts from those platforms and may set their own cookies once loaded. If your site needs cookie-consent gating, you'll want to load those scripts through your consent-management plugin instead of (or in addition to) this one. YouTube's "privacy-enhanced" mode already avoids this for video embeds, and with on demand the page doesn't contact YouTube at all until play is pressed.
- A URL that doesn't match any of the four supported providers is left as an ordinary link — nothing else on the page is touched.
Extending
To add another provider (e.g. TikTok, Facebook), add a new preg_match
branch in replaceLink() in autoembed.php following the same pattern
as the existing ones, plus a corresponding toggle in autoembed.yaml and
blueprints.yaml.
Tests
From the plugin folder, with the plugin installed in a Grav site:
GRAV_ROOT=/path/to/grav php tests/autoembed-test.php
The tests check which links become embeds and which stay links.
Licence
MIT.

