Title: WP_oEmbed::fetch
Published: April 25, 2014
Last modified: February 24, 2026

---

# WP_oEmbed::fetch( string $provider, string $url, string|array $args ): object|false

## In this article

 * [Parameters](https://developer.wordpress.org/reference/classes/WP_oEmbed/fetch/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/classes/WP_oEmbed/fetch/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/WP_oEmbed/fetch/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/classes/WP_oEmbed/fetch/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/classes/WP_oEmbed/fetch/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/WP_oEmbed/fetch/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/WP_oEmbed/fetch/?output_format=md#wp--skip-link--target)

Connects to an oEmbed provider and returns the result.

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/WP_oEmbed/fetch/?output_format=md#parameters)󠁿

 `$provider`stringrequired

The URL to the oEmbed provider.

`$url`stringrequired

The URL to the content that is desired to be embedded.

`$args`string|arrayoptional

Additional arguments for retrieving embed HTML.
 See [wp_oembed_get()](https://developer.wordpress.org/reference/functions/wp_oembed_get/)
for accepted arguments. Default empty.

More Arguments from wp_oembed_get( … $args )

Additional arguments for retrieving embed HTML. Default empty.

 * `width` int|string
 * Optional. The `maxwidth` value passed to the provider URL.
 * `height` int|string
 * Optional. The `maxheight` value passed to the provider URL.
 * `discover` bool
 * Optional. Determines whether to attempt to discover link tags at the given URL
   for an oEmbed provider when the provider URL is not found in the built-in providers
   list. Default true.

## 󠀁[Return](https://developer.wordpress.org/reference/classes/WP_oEmbed/fetch/?output_format=md#return)󠁿

 object|false The result in the form of an object on success, false on failure.

## 󠀁[Source](https://developer.wordpress.org/reference/classes/WP_oEmbed/fetch/?output_format=md#source)󠁿

    ```php
    public function fetch( $provider, $url, $args = '' ) {
    	$args = wp_parse_args( $args, wp_embed_defaults( $url ) );

    	$provider = add_query_arg( 'maxwidth', (int) $args['width'], $provider );
    	$provider = add_query_arg( 'maxheight', (int) $args['height'], $provider );
    	$provider = add_query_arg( 'url', urlencode( $url ), $provider );
    	$provider = add_query_arg( 'dnt', 1, $provider );

    	/**
    	 * Filters the oEmbed URL to be fetched.
    	 *
    	 * @since 2.9.0
    	 * @since 4.9.0 The `dnt` (Do Not Track) query parameter was added to all oEmbed provider URLs.
    	 *
    	 * @param string $provider URL of the oEmbed provider.
    	 * @param string $url      URL of the content to be embedded.
    	 * @param array  $args     Optional. Additional arguments for retrieving embed HTML.
    	 *                         See wp_oembed_get() for accepted arguments. Default empty.
    	 */
    	$provider = apply_filters( 'oembed_fetch_url', $provider, $url, $args );

    	foreach ( array( 'json', 'xml' ) as $format ) {
    		$result = $this->_fetch_with_format( $provider, $format );
    		if ( is_wp_error( $result ) && 'not-implemented' === $result->get_error_code() ) {
    			continue;
    		}

    		return ( $result && ! is_wp_error( $result ) ) ? $result : false;
    	}

    	return false;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-oembed.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/class-wp-oembed.php#L534)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/class-wp-oembed.php#L534-L565)

## 󠀁[Hooks](https://developer.wordpress.org/reference/classes/WP_oEmbed/fetch/?output_format=md#hooks)󠁿

 [apply_filters( ‘oembed_fetch_url’, string $provider, string $url, array $args )](https://developer.wordpress.org/reference/hooks/oembed_fetch_url/)

Filters the oEmbed URL to be fetched.

## 󠀁[Related](https://developer.wordpress.org/reference/classes/WP_oEmbed/fetch/?output_format=md#related)󠁿

| Uses | Description | 
| [WP_oEmbed::_fetch_with_format()](https://developer.wordpress.org/reference/classes/wp_oembed/_fetch_with_format/)`wp-includes/class-wp-oembed.php` |

Fetches result from an oEmbed provider for a specific format and complete provider URL

  | 
| [wp_embed_defaults()](https://developer.wordpress.org/reference/functions/wp_embed_defaults/)`wp-includes/embed.php` |

Creates default array of embed parameters.

  | 
| [wp_parse_args()](https://developer.wordpress.org/reference/functions/wp_parse_args/)`wp-includes/functions.php` |

Merges user defined arguments into defaults array.

  | 
| [add_query_arg()](https://developer.wordpress.org/reference/functions/add_query_arg/)`wp-includes/functions.php` |

Retrieves a modified URL query string.

  | 
| [apply_filters()](https://developer.wordpress.org/reference/functions/apply_filters/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to a filter hook.

  | 
| [is_wp_error()](https://developer.wordpress.org/reference/functions/is_wp_error/)`wp-includes/load.php` |

Checks whether the given variable is a WordPress Error.

  |

[Show 4 more](https://developer.wordpress.org/reference/classes/WP_oEmbed/fetch/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/classes/WP_oEmbed/fetch/?output_format=md#)

| Used by | Description | 
| [WP_oEmbed::get_data()](https://developer.wordpress.org/reference/classes/wp_oembed/get_data/)`wp-includes/class-wp-oembed.php` |

Takes a URL and attempts to return the oEmbed data.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/WP_oEmbed/fetch/?output_format=md#changelog)󠁿

| Version | Description | 
| [2.9.0](https://developer.wordpress.org/reference/since/2.9.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_oembed%2Ffetch%2F)
before being able to contribute a note or feedback.