wc_make_phone_clickable( string $phone )

Convert plaintext phone number to clickable phone number.


Description Description

Remove formatting and allow "+". Example and specs: https://developer.mozilla.org/en/docs/Web/HTML/Element/a#Creating_a_phone_link


Parameters Parameters

$phone

(Required) Content to convert phone number.


Top ↑

Return Return

(string) Content with converted phone number.


Top ↑

Source Source

File: includes/wc-core-functions.php

function wc_make_phone_clickable( $phone ) {
	$number = trim( preg_replace( '/[^\d|\+]/', '', $phone ) );

	return $number ? '<a href="tel:' . esc_attr( $number ) . '">' . esc_html( $phone ) . '</a>' : '';
}

Top ↑

Changelog Changelog

Changelog
Version Description
3.1.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.