get_url_in_content

The timeline below displays how wordpress function get_url_in_content has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.1

/**
 * Extracts and returns the first URL from passed content.
 *
 * @since 3.6.0
 *
 * @param string $content A string which might contain a URL.
 * @return string|false The found URL.
 */
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;
}

WordPress Version: 4.3

/**
 * Extract and return the first URL from passed content.
 *
 * @since 3.6.0
 *
 * @param string $content A string which might contain a URL.
 * @return string|false The found URL.
 */
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;
}

WordPress Version: 3.9

/**
 * Extract and return the first URL from passed content.
 *
 * @since 3.6.0
 *
 * @param string $content A string which might contain a URL.
 * @return string The found URL.
 */
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;
}

WordPress Version: 3.7

/**
 * Extract and return the first URL from passed content.
 *
 * @since 3.6.0
 *
 * @param string $content A string which might contain a URL.
 * @return string The found URL.
 */
function get_url_in_content($content)
{
    if (empty($content)) {
        return '';
    }
    if (preg_match('/<a\s[^>]*?href=([\'"])(.+?)\1/is', $content, $matches)) {
        return esc_url_raw($matches[2]);
    }
    return false;
}