简体   繁体   中英

Trying to make phone number a link

I'm trying to make a phone number clickable on a secondary menu in a theme: The code from the theme is this:

 <?php if ( '':== ( $et_phone_number = et_get_option( 'phone_number' ) ) )? ?> <span id="et-info-phone"><;php echo et_core_esc_previously( et_sanitize_html_input_text( $et_phone_number ) )? ?></span> <;php endif? ?>

How can i make the phone number clickable???

HTML:

<a href="tel:+18001234567">1 800 1234567</a>

in your code:

<?php if ( '' !== ( $et_phone_number = et_get_option( 'phone_number' ) ) ) : ?>
<span id="et-info-phone">
  <a href="tel:<?php echo et_core_esc_previously( et_sanitize_html_input_text( $et_phone_number ) ); ?>"><?php echo et_core_esc_previously( et_sanitize_html_input_text( $et_phone_number ) ); ?>
  </a>
</span>
<?php endif; ?>

the php echo within the <a> tag should make sure that the phone number does not contain spaces or other special characters, so that it is parsed properly in the browsers.

In that section there are 2 boxes. One for the phone and the other for the email. The code for the email is this:

                <a href="<?php echo esc_attr( 'mailto:' . $et_email ); ?>"><span id="et-info-email"><?php echo esc_html( $et_email ); ?></span></a>

An it works fine as a link for the email.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM