get_url_in_content()
Extracts and returns the first URL from passed content.
No Hooks.
Return
String|false
. The found URL.
Usage
get_url_in_content( $content );
- $content(string) (required)
- A string which might contain a URL.
Changelog
Since 3.6.0 | Introduced. |
get_url_in_content() get url in content code WP 6.7.1
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; }