# Remove Autoplay From Embedded Videos

> Strips autoplay settings from YouTube and Vimeo embeds in posts, so videos only start when the visitor presses play.

- Type: PHP
- Runs: Frontend only
- Category: [Accessibility](https://wpide.com/library/category/accessibility/)
- Tags: video, autoplay, embeds
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/a11y-no-autoplay-embeds/

## Code

```php
$wpide_strip_autoplay = function ( $html ) {
    if ( false === stripos( $html, 'autoplay' ) || ! class_exists( 'WP_HTML_Tag_Processor' ) ) {
        return $html;
    }

    $tags = new WP_HTML_Tag_Processor( $html );

    while ( $tags->next_tag( 'iframe' ) ) {
        $src = (string) $tags->get_attribute( 'src' );

        if ( preg_match( '#(youtube\.com|youtube-nocookie\.com|player\.vimeo\.com)#i', $src ) ) {
            $tags->set_attribute( 'src', remove_query_arg( array( 'autoplay', 'mute', 'muted', 'background' ), $src ) );
        }

        $allow = (string) $tags->get_attribute( 'allow' );
        if ( $allow ) {
            $tags->set_attribute( 'allow', trim( preg_replace( '/\s*autoplay;?/i', '', $allow ) ) );
        }
    }

    return $tags->get_updated_html();
};

add_filter( 'embed_oembed_html', $wpide_strip_autoplay, 20 );
add_filter( 'the_content', $wpide_strip_autoplay, 20 );
```

## Notes

Background videos added as Cover blocks are not embeds and are not changed by this snippet.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Remove Autoplay From Embedded Videos" 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/
