• Resolved GeekGal

    (@geekgal)


    I am using the latest Genesis Sample Theme and I think their Contact Details widget is your code. If it is, how and where could I add/edit code to make the phone number field a live link (tel:614-555-5555) so it dials automatically on smartphones? Similar to how you have the email a live link that automatically opens in the user’s email client. Thanks.

    https://wordpress.org/plugins/contact-widgets/

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Jonathan Bardo

    (@jonathanbardo)

    Hey GeekGal,

    This could be done using a little bit of php in your theme functions.php:

    add_filter('wpcw_widget_contact_custom_fields', function( $fields ) {
    
    $fields['phone']['escaper'] = function( $value ) {
      return sprintf( '<a href="tel:%1$s">%1$s</a>', esc_attr( $value ) );
    };
    
    return $fields;
    
    });

    Let me know if that works for you.

    Thread Starter GeekGal

    (@geekgal)

    Thanks so much! It works like a charm.

    Thread Starter GeekGal

    (@geekgal)

    Hi Jonathan,
    Thanks so much for the last hack. Now client wants a second phone number to display. Could code be altered to read Phone: 614-555-55555 or 614-555-1212 in same field and both be live links? That might be a stretch, I know. Or could Fax field be replaced with Phone 2 and be live link? I know it’s a bit out of the ordinary. Thanks in advance.

    Plugin Author Jonathan Bardo

    (@jonathanbardo)

    Hey you can add as many phone fields as you want. Replace the previous snippet by the following to add a new phone field field:

    add_filter('wpcw_widget_contact_custom_fields', function( $fields ) {
    
    $fields['phone']['escaper'] = function( $value ) {
      return sprintf( '<a href="tel:%1$s">%1$s</a>', esc_attr( $value ) );
    };
    
    $fields['phone2'] = [
      'label' => __( 'Phone:', 'contact-widgets' ),
      'type'  => 'text',
      'escaper' => $fields['phone']['escaper'],
    ];
    
    return $fields;
    
    });
    Thread Starter GeekGal

    (@geekgal)

    Thanks Jonathan. You are such a dear person! That worked great, but the second phone is below the address. Wish I new php, but alas, I am a dunce with that. How can I get Phone 2 under Phone? Thanks so much in advance. Here’s a screenshot – http://screencast.com/t/TT4RqqL6xw

    Plugin Author Jonathan Bardo

    (@jonathanbardo)

    Hey Geekgal,

    Simply drag and drop the new field to the position you like using the drag handle to the right of the field.

    See: http://prnt.sc/c21d0m

    Have a great day!

    Thread Starter GeekGal

    (@geekgal)

    Duh! Thanks. That was easy. Now this is only fluff, but client asked if first phone field could display as Office. I got phone 2 to display as Mobile. See screenshot. http://screencast.com/t/Mdl0GJHZ

    I need to send you a Starbucks coffee for your time.

    Plugin Author Jonathan Bardo

    (@jonathanbardo)

    Hey GeekGal,

    To change the phone label we need to modify the above function just a little bit.

    Here we go:

    add_filter('wpcw_widget_contact_custom_fields', function( $fields ) {
    
    $fields['phone']['label'] = 'Office:';
    
    $fields['phone']['escaper'] = function( $value ) {
      return sprintf( '<a href="tel:%1$s">%1$s</a>', esc_attr( $value ) );
    };
    
    $fields['phone2'] = [
      'label' => __( 'Mobile:', 'contact-widgets' ),
      'type'  => 'text',
      'escaper' => $fields['phone']['escaper'],
    ];
    
    return $fields;
    
    });

    If you can take a little of your time to write us a review it would mean a lot to us. (https://wordpress.org/support/view/plugin-reviews/contact-widgets)

    Thank you!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘How to edit phone field to be live link’ is closed to new replies.