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

---

# wp_extract_urls( string $content ): string[]

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/wp_extract_urls/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/wp_extract_urls/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/wp_extract_urls/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/wp_extract_urls/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/wp_extract_urls/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/wp_extract_urls/?output_format=md#user-contributed-notes)

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

Uses RegEx to extract URLs from arbitrary content.

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

 `$content`stringrequired

Content to extract URLs from.

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

 string[] Array of URLs found in passed string.

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

    ```php
    function wp_extract_urls( $content ) {
    	preg_match_all(
    		"#([\"']?)("
    			. '(?:([\w-]+:)?//?)'
    			. '[^\s()<>]+'
    			. '[.]'
    			. '(?:'
    				. '\([\w\d]+\)|'
    				. '(?:'
    					. "[^`!()\[\]{}:'\".,<>«»“”‘’\s]|"
    					. '(?:[:]\d+)?/?'
    				. ')+'
    			. ')'
    		. ")\\1#",
    		$content,
    		$post_links
    	);

    	$post_links = array_unique(
    		array_map(
    			static function ( $link ) {
    				// Decode to replace valid entities, like &amp;.
    				$link = html_entity_decode( $link );
    				// Maintain backward compatibility by removing extraneous semi-colons (`;`).
    				return str_replace( ';', '', $link );
    			},
    			$post_links[2]
    		)
    	);

    	return array_values( $post_links );
    }
    ```

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

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

| Used by | Description | 
| [do_enclose()](https://developer.wordpress.org/reference/functions/do_enclose/)`wp-includes/functions.php` |

Checks content for video and audio links to add as enclosures.

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

Pings back the links found in a post.

  |

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

| Version | Description | 
| [6.0.0](https://developer.wordpress.org/reference/since/6.0.0/) | Fixes support for HTML entities (Trac 30580). | 
| [3.7.0](https://developer.wordpress.org/reference/since/3.7.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/wp_extract_urls/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 3 content](https://developer.wordpress.org/reference/functions/wp_extract_urls/?output_format=md#comment-content-4727)
 2.    [Sean Leavey](https://profiles.wordpress.org/seanleavey/)  [  5 years ago  ](https://developer.wordpress.org/reference/functions/wp_extract_urls/#comment-4727)
 3.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_extract_urls%2F%23comment-4727)
     Vote results for this note: 1[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_extract_urls%2F%23comment-4727)
 4.  This doesn’t work for localhost URLs without TLDs:
 5.      ```php
         <a href="http://localhost.com:8889/?p=9">hi</a&gt;  // Matches.
         <a href="http://localhost:8889/?p=9">hi</a&gt;      // Doesn't match.
         ```
     
 6.  (See [this ticket](https://core.trac.wordpress.org/ticket/52235#ticket).)
 7.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_extract_urls%2F%3Freplytocom%3D4727%23feedback-editor-4727)
 8.   [Skip to note 4 content](https://developer.wordpress.org/reference/functions/wp_extract_urls/?output_format=md#comment-content-1541)
 9.    [Codex](https://profiles.wordpress.org/codex/)  [  10 years ago  ](https://developer.wordpress.org/reference/functions/wp_extract_urls/#comment-1541)
 10. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_extract_urls%2F%23comment-1541)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_extract_urls%2F%23comment-1541)
 11. **Example**
 12. This Code:
 13.     ```php
         $string = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin elementum quis lacus in accumsan. Sed sed lacus odio. Sed ullamcorper, nibh et dignissim convallis, lacus tellus pellentesque ipsum, et interdum purus urna ultricies justo. Phasellus blandit eros nec lectus vestibulum consequat. Cras faucibus turpis sed ante commodo cursus. Duis vitae ligula vulputate, varius mi vel, facilisis est. Nulla id mollis ipsum. Nunc faucibus augue vel erat luctus sodales. Curabitur gravida vulputate nulla sed aliquam. Ut posuere mollis mauris, et placerat diam cursus vitae. Vivamus eros arcu, lobortis id sapien at, tempus tristique nunc. Praesent sollicitudin vulputate lorem, vitae vestibulum nisi pretium non. http://example.com is a cool site.';
     
         $urls = wp_extract_urls( $string );
         ```
     
 14. Will return an array like this:
 15.     ```php
         array( 0 => 'http://example.com' )
         ```
     
 16.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_extract_urls%2F%3Freplytocom%3D1541%23feedback-editor-1541)

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