On this page
get_url_in_content( string $content ): string|false
Extracts and returns the first URL from passed content.
Parameters
$contentstring Required-
A string which might contain a URL.
Return
string|false The found URL.
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;
}
Related
Uses
| Uses | Description |
|---|---|
| sanitize_url() wp-includes/formatting.php | Sanitizes a URL for database or redirect usage. |
Changelog
| Version | Description |
|---|---|
| 3.6.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/get_url_in_content