Title: WP_oEmbed::discover
Published: April 25, 2014
Last modified: May 20, 2026

---

# WP_oEmbed::discover( string $url ): string|false

## In this article

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

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

Attempts to discover link tags at the given URL for an oEmbed provider.

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

 `$url`stringrequired

The URL that should be inspected for discovery `<link>` tags.

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

 string|false The oEmbed provider URL on success, false on failure.

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

    ```php
    public function discover( $url ) {
    	$providers = array();
    	$args      = array(
    		'limit_response_size' => 153600, // 150 KB
    	);

    	/**
    	 * Filters oEmbed remote get arguments.
    	 *
    	 * @since 4.0.0
    	 *
    	 * @see WP_Http::request()
    	 *
    	 * @param array  $args oEmbed remote get arguments.
    	 * @param string $url  URL to be inspected.
    	 */
    	$args = apply_filters( 'oembed_remote_get_args', $args, $url );

    	// Fetch URL content.
    	$request = wp_safe_remote_get( $url, $args );
    	$html    = wp_remote_retrieve_body( $request );
    	if ( $html ) {

    		/**
    		 * Filters the link types that contain oEmbed provider URLs.
    		 *
    		 * @since 2.9.0
    		 *
    		 * @param string[] $format Array of oEmbed link types. Accepts 'application/json+oembed',
    		 *                         'text/xml+oembed', and 'application/xml+oembed' (incorrect,
    		 *                         used by at least Vimeo).
    		 */
    		$linktypes = apply_filters(
    			'oembed_linktypes',
    			array(
    				'application/json+oembed' => 'json',
    				'text/xml+oembed'         => 'xml',
    				'application/xml+oembed'  => 'xml',
    			)
    		);

    		// Strip <body>.
    		$html_head_end = stripos( $html, '</head>' );
    		if ( $html_head_end ) {
    			$html = substr( $html, 0, $html_head_end );
    		}

    		// Do a quick check.
    		$tagfound = false;
    		foreach ( $linktypes as $linktype => $format ) {
    			if ( stripos( $html, $linktype ) ) {
    				$tagfound = true;
    				break;
    			}
    		}

    		if ( $tagfound && preg_match_all( '#<link([^<>]+)/?>#iU', $html, $links ) ) {
    			foreach ( $links[1] as $link ) {
    				$atts = shortcode_parse_atts( $link );

    				if ( ! empty( $atts['type'] ) && ! empty( $linktypes[ $atts['type'] ] ) && ! empty( $atts['href'] ) ) {
    					$providers[ $linktypes[ $atts['type'] ] ] = htmlspecialchars_decode( $atts['href'] );

    					// Stop here if it's JSON (that's all we need).
    					if ( 'json' === $linktypes[ $atts['type'] ] ) {
    						break;
    					}
    				}
    			}
    		}
    	}

    	// JSON is preferred to XML.
    	if ( ! empty( $providers['json'] ) ) {
    		return $providers['json'];
    	} elseif ( ! empty( $providers['xml'] ) ) {
    		return $providers['xml'];
    	} else {
    		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/7.0/src/wp-includes/class-wp-oembed.php#L435)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/class-wp-oembed.php#L435-L515)

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

 [apply_filters( ‘oembed_linktypes’, string[] $format )](https://developer.wordpress.org/reference/hooks/oembed_linktypes/)

Filters the link types that contain oEmbed provider URLs.

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

Filters oEmbed remote get arguments.

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

| Uses | Description | 
| [stripos()](https://developer.wordpress.org/reference/functions/stripos/)`wp-includes/class-pop3.php` |  | 
| [wp_safe_remote_get()](https://developer.wordpress.org/reference/functions/wp_safe_remote_get/)`wp-includes/http.php` |

Retrieves the raw response from a safe HTTP request using the GET method.

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

Retrieves only the body from the raw response.

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

Retrieves all attributes from the shortcodes tag.

  | 
| [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.

  |

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

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

Takes a URL and returns the corresponding oEmbed provider’s URL, if there is one.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/WP_oEmbed/discover/?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%2Fdiscover%2F)
before being able to contribute a note or feedback.