get_url_in_content( string $content ): string|false

Extracts and returns the first URL from passed content.


Parameters

$content string Required
A string which might contain a URL.

Top ↑

Return

string|false The found URL.


Top ↑

Source

File: wp-includes/formatting.php. View all references

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

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

	return false;
}


Top ↑

Changelog

Changelog
Version Description
3.6.0 Introduced.

Top ↑

User Contributed Notes

You must log in before being able to contribute a note or feedback.