Using WordPress ‘make_clickable()’ PHP function

The make_clickable() WordPress PHP function converts plaintext URLs, ftp addresses, and email addresses into clickable HTML links.

Usage

make_clickable($text);

Input:

Visit our website: https://www.example.com and email us at [email protected]

Output:

Visit our website: <a href="https://www.example.com" rel="nofollow">https://www.example.com</a> and email us at <a href="mailto:[email protected]">[email protected]</a>

Parameters

  • $text (string) – The content to convert URLs, ftp addresses, and email addresses into clickable links.

More information

See WordPress Developer Resources: make_clickable

Examples

Converting a URL in a paragraph

Explanation: This example shows how to use make_clickable() to convert URLs within a paragraph.

Code:

$text = '<p>Visit our website for more info: https://www.example.com</p>';
echo make_clickable($text);

Converting multiple URLs

Explanation: This example demonstrates how to use make_clickable() to convert multiple URLs within a string.

Code:

$string = 'Check out these websites: https://www.example1.com, https://www.example2.com, and https://www.example3.com.';
echo make_clickable($string);

Converting an email address

Explanation: This example shows how to use make_clickable() to convert an email address within a string.

Code:

$string = 'For any inquiries, email us at [email protected]';
echo make_clickable($string);

Converting a mix of URLs and email addresses

Explanation: This example shows how to use make_clickable() to convert both URLs and email addresses within a string.

Code:

$string = 'Visit our website at https://www.example.com and send us an email at [email protected]';
echo make_clickable($string);

Converting URLs in a list

Explanation: This example demonstrates how to use make_clickable() to convert URLs within a list.

Code:

$text = '<ul><li>https://www.example1.com</li><li>https://www.example2.com</li><li>https://www.example3.com</li></ul>';
echo make_clickable($text);