# Load Vimeo Videos Only After a Click

> Replaces embedded Vimeo players with a lightweight placeholder showing the video title, so nothing is loaded from Vimeo until the visitor clicks to play.

- Type: PHP
- Runs: Frontend only
- Category: [Privacy & Cookies](https://wpide.com/library/category/privacy/)
- Tags: vimeo, embeds, gdpr
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/privacy-vimeo-click-to-load/

## Code

```php
add_filter( 'embed_oembed_html', function ( $html, $url ) {
    if ( false === stripos( $url, 'vimeo.com' ) || ! preg_match( '#<iframe[^>]+src="([^"]*player\.vimeo\.com[^"]*)"#i', $html, $src ) ) {
        return $html;
    }

    $title = preg_match( '#title="([^"]*)"#i', $html, $t ) ? html_entity_decode( $t[1], ENT_QUOTES ) : 'Vimeo video';
    $player = add_query_arg( array( 'autoplay' => 1, 'dnt' => 1 ), html_entity_decode( $src[1] ) );

    return sprintf(
        '<div class="wpide-vimeo" data-src="%1$s" style="position:relative;aspect-ratio:16/9;background:#1a2e3b;color:#fff;display:flex;align-items:center;justify-content:center;flex-direction:column;gap:10px;padding:16px;text-align:center;"><p style="margin:0;font-weight:600">%2$s</p><button type="button" class="wpide-vimeo-play" style="padding:10px 18px;border:0;border-radius:6px;background:#00adef;color:#fff;cursor:pointer;">Play video from Vimeo</button><small>Vimeo will receive your IP address when the video loads.</small></div>',
        esc_url( $player ),
        esc_html( $title )
    );
}, 20, 2 );

add_action( 'wp_footer', function () {
    ?>
<script>
document.addEventListener('click', function (e) {
    var btn = e.target.closest ? e.target.closest('.wpide-vimeo-play') : null;
    if (!btn) { return; }
    var box = btn.closest('.wpide-vimeo');
    var frame = document.createElement('iframe');
    frame.src = box.getAttribute('data-src');
    frame.title = box.querySelector('p').textContent;
    frame.allow = 'autoplay; fullscreen; picture-in-picture';
    frame.allowFullscreen = true;
    frame.style.cssText = 'position:absolute;inset:0;width:100%;height:100%;border:0;';
    box.replaceChildren(frame);
    frame.focus();
});
</script>
    <?php
} );
```

## Notes

The placeholder uses no image from Vimeo on purpose, so no request reaches Vimeo before the click.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Load Vimeo Videos Only After a Click" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
