Title: make_clickable
Published: April 25, 2014
Last modified: May 20, 2026

---

# make_clickable( string $text ): string

## In this article

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

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

Converts plaintext URI to HTML links.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/make_clickable/?output_format=md#description)󠁿

Converts URI, www and ftp, and email addresses. Finishes by fixing links within 
links.

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

 `$text`stringrequired

Content to convert URIs.

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

 string Content with converted URIs.

## 󠀁[More Information](https://developer.wordpress.org/reference/functions/make_clickable/?output_format=md#more-information)󠁿

This function can be fed long strings with URIs and email links and will convert
them into clickable links. You are not limited to feeding it just the link text 
itself (see the long string in the example above).

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

    ```php
    function make_clickable( $text ) {
    	$r               = '';
    	$textarr         = preg_split( '/(<[^<>]+>)/', $text, -1, PREG_SPLIT_DELIM_CAPTURE ); // Split out HTML tags.
    	$nested_code_pre = 0; // Keep track of how many levels link is nested inside <pre> or <code>.
    	foreach ( $textarr as $piece ) {

    		if ( preg_match( '|^<code[\s>]|i', $piece )
    			|| preg_match( '|^<pre[\s>]|i', $piece )
    			|| preg_match( '|^<script[\s>]|i', $piece )
    			|| preg_match( '|^<style[\s>]|i', $piece )
    		) {
    			++$nested_code_pre;
    		} elseif ( $nested_code_pre
    			&& ( '</code>' === strtolower( $piece )
    				|| '</pre>' === strtolower( $piece )
    				|| '</script>' === strtolower( $piece )
    				|| '</style>' === strtolower( $piece )
    			)
    		) {
    			--$nested_code_pre;
    		}

    		if ( $nested_code_pre
    			|| empty( $piece )
    			|| ( '<' === $piece[0] && ! preg_match( '|^<\s*[\w]{1,20}+://|', $piece ) )
    		) {
    			$r .= $piece;
    			continue;
    		}

    		// Long strings might contain expensive edge cases...
    		if ( 10000 < strlen( $piece ) ) {
    			// ...break it up.
    			foreach ( _split_str_by_whitespace( $piece, 2100 ) as $chunk ) { // 2100: Extra room for scheme and leading and trailing parentheses.
    				if ( 2101 < strlen( $chunk ) ) {
    					$r .= $chunk; // Too big, no whitespace: bail.
    				} else {
    					$r .= make_clickable( $chunk );
    				}
    			}
    		} else {
    			$ret = " $piece "; // Pad with whitespace to simplify the regexes.

    			$url_clickable = '~
    				([\\s(<.,;:!?])                                # 1: Leading whitespace, or punctuation.
    				(                                              # 2: URL.
    					[\\w]{1,20}+://                                # Scheme and hier-part prefix.
    					(?=\S{1,2000}\s)                               # Limit to URLs less than about 2000 characters long.
    					[\\w\\x80-\\xff#%\\~/@\\[\\]*(+=&$-]*+         # Non-punctuation URL character.
    					(?:                                            # Unroll the Loop: Only allow punctuation URL character if followed by a non-punctuation URL character.
    						[\'.,;:!?)]                                    # Punctuation URL character.
    						[\\w\\x80-\\xff#%\\~/@\\[\\]*(+=&$-]++         # Non-punctuation URL character.
    					)*
    				)
    				(\)?)                                          # 3: Trailing closing parenthesis (for parenthesis balancing post processing).
    				(\\.\\w{2,6})?                                 # 4: Allowing file extensions (e.g., .jpg, .png).
    			~xS';
    			/*
    			 * The regex is a non-anchored pattern and does not have a single fixed starting character.
    			 * Tell PCRE to spend more time optimizing since, when used on a page load, it will probably be used several times.
    			 */

    			$ret = preg_replace_callback( $url_clickable, '_make_url_clickable_cb', $ret );

    			$ret = preg_replace_callback( '#([\s>])((www|ftp)\.[\w\\x80-\\xff\#$%&~/.\-;:=,?@\[\]+]+)#is', '_make_web_ftp_clickable_cb', $ret );
    			$ret = preg_replace_callback( '#([\s>])([.0-9a-z_+-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,})#i', '_make_email_clickable_cb', $ret );

    			$ret = substr( $ret, 1, -1 ); // Remove our whitespace padding.
    			$r  .= $ret;
    		}
    	}

    	// Cleanup of accidental links within links.
    	return preg_replace( '#(<a([ \r\n\t]+[^>]+?>|>))<a [^>]+?>([^>]+?)</a></a>#i', '$1$3</a>', $r );
    }
    ```

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

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

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

Breaks a string into chunks by splitting at whitespace characters.

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

Converts plaintext URI to HTML links.

  |

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

Converts plaintext URI to HTML links.

  |

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

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

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

 1.   [Skip to note 3 content](https://developer.wordpress.org/reference/functions/make_clickable/?output_format=md#comment-content-293)
 2.    [Nicola Mustone](https://profiles.wordpress.org/nicolamustone/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/make_clickable/#comment-293)
 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%2Fmake_clickable%2F%23comment-293)
     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%2Fmake_clickable%2F%23comment-293)
 4.  This example shows how to use `make_clickable` with a string of text to turn any
     URLs within into links.
 5.      ```php
         <?php echo make_clickable( '<p>To find out more about this function, visit this link: https://developer.wordpress.org/reference/functions/make_clickable/</p&gt;' ); ?>
         ```
     
 6.  The result will be:
 7.      ```php
         <p>To find out more about this function, visit this link: <a href="https://developer.wordpress.org/reference/functions/make_clickable/&quot; rel="nofollow">https://developer.wordpress.org/reference/functions/make_clickable/</a></p&gt;
         ```
     
 8.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fmake_clickable%2F%3Freplytocom%3D293%23feedback-editor-293)
 9.   [Skip to note 4 content](https://developer.wordpress.org/reference/functions/make_clickable/?output_format=md#comment-content-1336)
 10.   [Codex](https://profiles.wordpress.org/codex/)  [  10 years ago  ](https://developer.wordpress.org/reference/functions/make_clickable/#comment-1336)
 11. [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%2Fmake_clickable%2F%23comment-1336)
     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%2Fmake_clickable%2F%23comment-1336)
 12. **Display all URLs in clickable links**
 13.     ```php
         $string = "This is a long text that contains some links like http://www.wordpress.org and http://www.wordpress.com .";
     
         echo make_clickable( $string ); 
         ```
     
 14.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fmake_clickable%2F%3Freplytocom%3D1336%23feedback-editor-1336)

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