Add a Click-to-Call Button Next to the Divi Mobile Menu Button

Written by Dan Mossop

Adding a click-to-call button next to the Divi mobile menu button is a great way to make it easier for your visitors to contact you. This setup ensures that your phone link is visible and accessible, particularly on mobile devices where users are more likely to use their phones to call.

To achieve this, follow these steps:

Step 1: Add PHP Code

First, add the following PHP code to your child theme's functions.php file or use a plugin like Code Snippets to insert it:

add_action('et_header_top', 'db_add_phone_link_before_hamburger');

function db_add_phone_link_before_hamburger() {
    echo <<<END
<a id="db-info-phone-main" href="tel:0412341234" aria-label="Call us">
<span style="display:none;">Phone</span>
</a>
END;
}

This snippet adds a clickable phone link before the hamburger menu, which ensures you have a functional click-to-call button. The aria-label attribute enhances accessibility by providing a description for screen readers.

Step 2: Add Custom CSS

Next, style the button by adding the following CSS to WP Admin > Divi > Theme Options > General > Custom CSS:

/* === Add phone icon next to mobile menu button === */

/* Position the icon */
#db-info-phone-main {
	display: inline-block;    
	position: relative;
	float: right;
	top: 4px;
	right: 60px;
	width: 0;
}

/* Style the icon */
#db-info-phone-main:before {
	font-family: ETmodules; 
	content: '\e090'; 
	cursor: pointer; 
}

/* Hide the icon on desktop */
@media (min-width: 981px) {
	#db-info-phone-main {
		display: none;
	}
}

/* === END: Add phone icon next to mobile menu button === */

Explanation

  1. Position the Icon: The #db-info-phone-main selector positions the icon next to the mobile menu button. It uses relative positioning and floats right to place it correctly.
  2. Style the Icon: The :before pseudo-element is used to display the icon. The font-family is set to ETmodules to use Divi's icon font, and the content value is the icon code.
  3. Responsive Behavior: The @media query hides the icon on screens wider than 980px, ensuring it's only visible on mobile devices.

Conclusion

With these steps, you now have a functional and stylish click-to-call button next to your Divi mobile menu button, making it easier for your mobile visitors to reach you with a single tap. This simple addition enhances user experience and supports better engagement with your site.

We may earn a commission when you visit links on our website.

Run PHP Code Directly in your Divi Layouts

Unlock endless customization, automation, and dynamic functionality by seamlessly adding PHP code to your Divi pages and posts with the Divi PHP Code Module. Style, preview, and debug your PHP creations directly in the visual builder with robust error handling and enhanced security.

Latest Posts

Add a Visible Shadow to Divi Gallery Lightbox Arrows

Give the lightbox navigation arrows in your Divi galleries a stylish pop and improve their visibility by adding a shadow beneath the arrows. This quick guide will show you how to make your navigation arrows stand out against the lightbox overlay.Add a Visible Shadow...

Adjust Lightbox Arrow Size in Divi Gallery

Customize the size of the navigation arrows that appear in your gallery lightbox so they’re easier to see and aligned with your site’s design. Whether you want larger, more accessible controls or a subtler look, setting a precise arrow size creates a more polished...

Change Lightbox Arrow Color in the Divi Gallery Module

Make the lightbox navigation arrows in your Divi Gallery match your brand and stand out against your images by assigning a custom color. This improves visual consistency, enhances accessibility with better contrast, and elevates the overall browsing experience for...

Change the Divi Gallery Module Grid Image Scaling

Divi’s Gallery module offers a great way to showcase images, but it can sometimes stretch or crop them in unwanted ways. This article explains how to manage the module’s image scaling behavior to ensure your images are displayed at the correct size and aspect...

About Dan Mossop

Dan is a Scottish-born web developer, now living in Brisbane with his wife and son. He has been sharing tips and helping users with Divi since 2014. He created Divi Booster, the first Divi plugin, and continues to develop it along with 20+ other Divi plugins. Dan has a PhD in Computer Science, a background in web security and likes a lot of stuff, 

0 Comments

Submit a Comment

Comments are manually moderated and approved at the time they are answered. A preview is shown while pending but may disappear if your are cookies cleared - don't worry though, the comment is still in the queue.

Your email address will not be published. Required fields are marked *.