Using WordPress ‘oembed_remote_get_args’ PHP filter

The oembed_remote_get_args WordPress PHP filter allows you to modify oEmbed remote get arguments.

Usage

add_filter('oembed_remote_get_args', 'my_custom_oembed_remote_get_args', 10, 2);

function my_custom_oembed_remote_get_args($args, $url) {
    // your custom code here
    return $args;
}

Parameters

  • $args (array): oEmbed remote get arguments.
  • $url (string): URL to be inspected.

More information

See WordPress Developer Resources: oembed_remote_get_args

Examples

Add a custom user agent

Modify the user agent for oEmbed requests:

add_filter('oembed_remote_get_args', 'change_oembed_user_agent', 10, 2);

function change_oembed_user_agent($args, $url) {
    $args['user-agent'] = 'My Custom User Agent';
    return $args;
}

Increase the timeout

Increase the timeout for oEmbed requests:

add_filter('oembed_remote_get_args', 'increase_oembed_timeout', 10, 2);

function increase_oembed_timeout($args, $url) {
    $args['timeout'] = 15;
    return $args;
}

Add a custom HTTP header

Add a custom HTTP header to oEmbed requests:

add_filter('oembed_remote_get_args', 'add_custom_http_header', 10, 2);

function add_custom_http_header($args, $url) {
    $args['headers']['X-Custom-Header'] = 'custom_value';
    return $args;
}

Change the SSL verification

Disable SSL verification for oEmbed requests:

add_filter('oembed_remote_get_args', 'disable_ssl_verification', 10, 2);

function disable_ssl_verification($args, $url) {
    $args['sslverify'] = false;
    return $args;
}

Remove cookies

Remove cookies from oEmbed requests:

add_filter('oembed_remote_get_args', 'remove_cookies', 10, 2);

function remove_cookies($args, $url) {
    $args['cookies'] = array();
    return $args;
}