Answer the question
In order to leave comments, you need to log in
How to remove extra characters in phone link when displaying in WordPress (backend)?
Can you please tell me how to remove extra characters in the link to the phone when displaying in WordPress?
I am displaying the phone number via theme-options.php. The phone number contains spaces and the characters "(" and ")". And in order for the number in the link (href="tel:....") to be correct, these characters must not be there, so you need to cut them out with some function, tell me.
<a href="tel:<?php
$options = get_option('sample_theme_options');
echo $options['phonetext']; ?>">
<?php
$options = get_option('sample_theme_options');
echo $options['phonetext']; ?>
</a>
Answer the question
In order to leave comments, you need to log in
Most reliable using regular expressions, for example using the preg_replace function
Solved the problem this way:
<a href="tel:+<?php
$options = get_option('sample_theme_options');
$options = preg_replace('![^0-9]+!', '', $options);
echo $options['phonetext']; ?>">
<?php
$options = get_option('sample_theme_options');
echo $options['phonetext']; ?>
</a>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question