Created
February 13, 2026 16:22
-
-
Save LeMiira/fda32968ad15df384b8de54fab373312 to your computer and use it in GitHub Desktop.
WordPress shortcode that retrieves an ACF field named "video" and embeds a Vimeo video. Accepts either a full Vimeo URL or a numeric Vimeo ID and forces autoplay, muted, loop, and other player parameters. Responsive 16:9 output.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Shortcode: [acf_vimeo field="my_acf_video_field"] | |
| function acf_vimeo_shortcode($atts) { | |
| $atts = shortcode_atts([ | |
| 'field' => 'video' | |
| ], $atts); | |
| $value = get_field($atts['field']); | |
| if (!$value) return ''; | |
| $vimeo_id = ''; | |
| // If numeric → ID | |
| if (is_numeric($value)) { | |
| $vimeo_id = $value; | |
| } else { | |
| if (preg_match('/vimeo\.com\/(?:video\/)?([0-9]+)/', $value, $matches)) { | |
| $vimeo_id = $matches[1]; | |
| } | |
| } | |
| if (!$vimeo_id) return ''; | |
| // Force parameters | |
| $params = http_build_query([ | |
| 'autoplay' => 1, | |
| 'loop' => 1, | |
| 'autopause' => 0, | |
| 'color' => '00adef', | |
| 'portrait' => 0, | |
| 'byline' => 1, | |
| 'title' => 1, | |
| 'controls' => 0, | |
| 'muted' => 1 | |
| ]); | |
| $src = "https://player.vimeo.com/video/{$vimeo_id}?{$params}"; | |
| return '<div class="acf-vimeo-wrapper" style="position:relative;padding-bottom:56.25%;height:0;overflow:hidden;"> | |
| <iframe src="' . esc_url($src) . '" | |
| style="position:absolute;top:0;left:0;width:100%;height:100%;" | |
| frameborder="0" | |
| allow="autoplay; fullscreen; picture-in-picture" | |
| allowfullscreen> | |
| </iframe> | |
| </div>'; | |
| } | |
| add_shortcode('acf_vimeo', 'acf_vimeo_shortcode'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment