get_url_in_content() WordPress Function
This function allows you to get the URL of the first link in the post content.
get_url_in_content( string $content ) #
Extracts and returns the first URL from passed content.
Parameters
- $content
(string)(Required)A string which might contain a URL.
Return
(string|false) The found URL.
Source
File: wp-includes/formatting.php
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; }
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
Version | Description |
---|---|
3.6.0 | Introduced. |