Adding SMS to wordpress menu

Hello!

Been trying to figure out a way to add SMS to a menu custom link in the Wordpress menu.

The url I am using sms://+18889122126 so in mobile it triggers the customer’s SMS app. The problem occurs when I add a custom link with this as the URL. It vanishes. I’ve tried on different Pro websites and I can’t seem to get it to work. Am I doing something wrong or is the wordpress menu function not working properly?

Add the following script but replace 555 with the actual menu item class and put the phone number in.

<script>
jQuery(window).load(function(){
jQuery('.menu-item-555 a').attr('href','sms:555-555-5555');
});
</script>

Appreciate the response. Where exactly should I add the script? I added it to functions.php but the site crashed.

Use this code in your functions.php

add_action('wp_head','my_code');
function my_code () { ?>

<script>
jQuery(window).load(function(){
jQuery('.menu-item-555 a').attr('href','sms:555-555-5555');
});
</script>

<?php }

@lp-ben

Thanks for helping out. Cheers!

I tried it - no crash this time but when adding the “sms://+18889122126” to menu. It still vanishes after saving. Again, really appreciate the suggestions so far. Any other thoughts?

Hi There,

Please try without the //

Just sms:+18889122126

Let us know how it goes.

Tried that - same result. :frowning:

I also tried changing up with the phone number in the script (add a 1, remove the -'s, etc) but everything I have tried continues to deliver the same result. An empty field.

Add a custom link to the menu with a blank URL and whatever you want the label to be. Inspect it on the front end to get the class and add it to the script below where it says menu-item, then put that code into your functions and you’re good.

add_action('wp_head','my_code');
    function my_code () { ?>

    <script>
    jQuery(window).load(function(){
    jQuery('.menu-item-555 a').attr('href','sms:+18889122126');
    });
    </script>

    <?php }

oooooooooooooooooooooooooh! i wondered how the number 555 came to be in the menu item, my bad!

It works great - thanks for the help!

1 Like

Not a problem, glad it’s working for you.

Thanks for helping @lp-ben :slight_smile:

1 Like