Title: get_url_in_content
Published: April 25, 2014
Last modified: February 24, 2026

---

# get_url_in_content( string $content ): string|false

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/get_url_in_content/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/get_url_in_content/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/get_url_in_content/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/get_url_in_content/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/get_url_in_content/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/get_url_in_content/?output_format=md#wp--skip-link--target)

Extracts and returns the first URL from passed content.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/get_url_in_content/?output_format=md#parameters)󠁿

 `$content`stringrequired

A string which might contain an `A` element with a non-empty `href` attribute.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/get_url_in_content/?output_format=md#return)󠁿

 string|false Database-escaped URL via [esc_url()](https://developer.wordpress.org/reference/functions/esc_url/)
if found, otherwise `false`.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/get_url_in_content/?output_format=md#source)󠁿

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

    	$processor = new WP_HTML_Tag_Processor( $content );
    	while ( $processor->next_tag( 'A' ) ) {
    		$href = $processor->get_attribute( 'href' );
    		if ( is_string( $href ) && '' !== $href ) {
    			return sanitize_url( $href );
    		}
    	}

    	return false;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/formatting.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/formatting.php#L5825)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/formatting.php#L5825-L5839)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/get_url_in_content/?output_format=md#related)󠁿

| Uses | Description | 
| [WP_HTML_Tag_Processor::__construct()](https://developer.wordpress.org/reference/classes/wp_html_tag_processor/__construct/)`wp-includes/html-api/class-wp-html-tag-processor.php` |

Constructor.

  | 
| [sanitize_url()](https://developer.wordpress.org/reference/functions/sanitize_url/)`wp-includes/formatting.php` |

Sanitizes a URL for database or redirect usage.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/get_url_in_content/?output_format=md#changelog)󠁿

| Version | Description | 
| [3.6.0](https://developer.wordpress.org/reference/since/3.6.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_url_in_content%2F)
before being able to contribute a note or feedback.