A WordPress-centric search engine for devs and theme authors



get_url_in_content ›

Since3.6.0
Deprecatedn/a
get_url_in_content ( $content )
Parameters:
  • (string) $content A string which might contain a URL.
    Required: Yes
Returns:
  • (string|false) The found URL.
Defined at:
Codex:

Extract and return the first URL from passed content.



Source

function get_url_in_content( $content ) {
	if ( empty( $content ) ) {
		return false;
	}

	if ( preg_match( '/<a\s[^>]*?href=([\'"])(.+?)\1/is', $content, $matches ) ) {
		return esc_url_raw( $matches[2] );
	}

	return false;
}