I've previously written about how to make the Divi header phone number into a clickable link. But what if you want to be able to trigger an SMS instead?
Unfortunately, the technique described in that post won't work as Divi strips the SMS protocol from links added via the phone number field.
We can instead add a new link alongside the phone / email links, using the following JavaScript code:
<script>
jQuery(function($){
if (!$('#et-info').length) {
$('#top-header > .container').prepend('<div id="et-info"></div>');
}
$('#et-info').prepend('<a class="et-info-sms" href="sms://+6112341234">SMS me</a>');
});
</script>
Related Post: Adding JavaScript / jQuery to Divi.
See this post for more info on the format of SMS links.
You may also wish to add an icon to your SMS link, a speech bubble icon for example. You can do that with the following CSS:
.et-info-sms:before {
content: '>';
font-family: 'ETModules';
margin-right: 4px;
}
Related Post: Adding CSS to the Divi Theme
I've tried to do this and nothing is popping up in the top header. Am I missing something? Was there an update that made this not work? Any help would be greatly appreciated.
Hi Tony, it looks like the code is still working in the latest Divi. There are a few reasons why it might not show.
One is if you aren't including a phone number / email alongside it. The original code relies on the existence of an HTML element that is added when a phone number / email is used. I've just updated the code so that it will add the element if not already present. This means that you should be able to use the SMS link without needing the phone / email to be present.
Another is caching – if you haven't already, try clearing the caches in any performance plugins you're running, then clear your browser cache to ensure you're seeing the latest version of the page.
If that doesn't help, perhaps you can send me a link to the site you're working o so that I can take a look?
Thanks!