2

I've been trying to figure this out for a few days now and I've now come to the understanding I need help.

I've never worked with the wordpress customizer but have been recently interested in adding additional text fields and image uploads to my themes I customize (I'm finding this quite difficult as not only do I need to learn the code for the customizer but then also have to figure out how to add it to a genesis theme - which there aren't too many articles on).

I'm trying to remove the "http://" from my url in my "Email Link" text box in a new panel I made.

I have the email text box and then the link where I've then added it to link to it (and the phone and possibly an address down the road).

enter image description here

So I've created the panel, then the text boxes. This is my email link text box (I haven't included the whole thing as there are many other pieces to it and I'm not sure that needs to be displayed as it's just the linking I need help on):

  // EMAIL
    $wp_customize->add_setting( 'header_utility_right_email_block', array(
         'default'           => '',
         'sanitize_callback' => 'sanitize_text'
    ) );
    $wp_customize->add_control( new WP_Customize_Control(
        $wp_customize,
        'header_utility_right_email_block',
            array(
                'label'    => __( 'Email', 'CHILD_THEME_NAME' ),
                'section'  => 'utility_bar_right',
                'settings' => 'header_utility_right_email_block',
                'type'     => 'text'
            )
        )
    );

    // EMAIL LINK
        $wp_customize->add_setting( 'header_utility_right_email_block_link', array(
             'default'           => '',
             'sanitize_callback' => 'sanitize_text'
        ) );
        $wp_customize->add_control( new WP_Customize_Control(
            $wp_customize,
            'header_utility_right_email_block_link',
                array(
                    'label'    => __( 'Email Link', 'CHILD_THEME_NAME' ),
                    'section'  => 'utility_bar_right',
                    'settings' => 'header_utility_right_email_block_link',
                    'type'     => 'text'
                )
            )
        );

then I have my phone and it in a function (for genesis) plus a lot more but I'll just give you the individual calling of it for the email and email link:

 if( get_theme_mod( 'header_utility_right_email_block') ) : ?>
        <div class='theme-utility-bar-right-email'>
            <a href="mailto:<?php echo esc_url( get_theme_mod( 'header_utility_right_email_block_link', '$protocols = null' ) ); ?>"><?php echo get_theme_mod( 'header_utility_right_email_block');?></a>
        </div>
        <?php endif; 

All works great! Other than the link itself for the email returns a mailto:http://myemail@email.com instead of mailto:myemail@email.com.

Is there a way to remove the http://? I've looked for some articles and found the $protocol addition but not sure how to use it and if it's even the right way to go about this. I'm not really a programmer so need help with the first jump on the functions and suck but then from there usually get the hang of it.

Any help on making this "http://" not default would be great!

2

Because an email isn't a URL; you need to prepend the protocol to the value you pass to esc_url:

<a href="<?php echo esc_url( 'mailto:' . get_theme_mod( 'header_utility_right_email_block_link' ) ) ?>" ...
  • Awesome. Thanks! I'd like to do more customizing in the theme this way, are there any good articles to read you know of that would teach me this and more maybe? – kia4567 May 26 '16 at 23:31
  • There's loads! The dev resource should help get you started. – TheDeadMedic May 27 '16 at 9:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.