Using WordPress ‘oembed_providers’ PHP filter

The oembed_providers WordPress PHP filter allows you to modify the list of sanctioned oEmbed providers. These providers are trusted and allowed to embed content like iframes, videos, JavaScript, and arbitrary HTML.

Usage

add_filter('oembed_providers', 'custom_oembed_providers');
function custom_oembed_providers($providers) {
    // Your custom code here

    return $providers;
}

Parameters

  • $providers (array[]): An array of arrays containing data about popular oEmbed providers.

More information

See WordPress Developer Resources: oembed_providers

Examples

Add a custom oEmbed provider

This example adds a custom oEmbed provider to the list of sanctioned providers.

add_filter('oembed_providers', 'add_custom_oembed_provider');
function add_custom_oembed_provider($providers) {
    $providers['https://example.com/embed/.*'] = array(
        'https://example.com/oembed',
        true
    );
    return $providers;
}

Remove a specific oEmbed provider

This example removes the YouTube oEmbed provider from the sanctioned providers list.

add_filter('oembed_providers', 'remove_youtube_oembed_provider');
function remove_youtube_oembed_provider($providers) {
    unset($providers['#https?://(www\.)?youtube\.com/watch#i']);
    return $providers;
}

Modify an existing oEmbed provider

This example modifies the Vimeo oEmbed provider, changing its endpoint URL.

add_filter('oembed_providers', 'modify_vimeo_oembed_provider');
function modify_vimeo_oembed_provider($providers) {
    $providers['#https?://(www\.)?vimeo\.com/.*#i'][0] = 'https://custom-vimeo-endpoint.com/oembed';
    return $providers;
}

Clear all oEmbed providers

This example clears all existing oEmbed providers, effectively disabling oEmbed support.

add_filter('oembed_providers', 'clear_oembed_providers');
function clear_oembed_providers($providers) {
    return array();
}

Add multiple custom oEmbed providers

This example adds multiple custom oEmbed providers to the sanctioned providers list.

add_filter('oembed_providers', 'add_multiple_custom_oembed_providers');
function add_multiple_custom_oembed_providers($providers) {
    $custom_providers = array(
        'https://custom1.com/embed/.*' => array(
            'https://custom1.com/oembed',
            true
        ),
        'https://custom2.com/embed/.*' => array(
            'https://custom2.com/oembed',
            true
        )
    );

    return array_merge($providers, $custom_providers);
}