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.

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.

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 *.

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

Latest From Divi Booster

Enable Automatic Looping for YouTube Videos in the Divi Video Module

Enabling automatic looping for YouTube videos in your Divi video module ensures that content plays seamlessly and continuously without interruption. This feature can enhance user engagement, highlight key information, or create dynamic visual effects on your website....

Hide Video Controls in Divi Video Module

Disabling YouTube video controls in the Divi Video Module helps create a seamless, distraction-free viewing experience for your site visitors. This approach is useful when you want full control over how your video content appears and is interacted with on the page, or...

Mute YouTube Videos by Default in the Divi Video Module

In the Divi Video Module, starting your YouTube videos muted by default can create a more user-friendly browsing experience on your webpage. It is particularly beneficial for reducing distractions, enhancing visitor engagement, and providing a seamless content preview...

Autoplay Videos in Divi Video Module

Enabling videos in your Divi video module to start playing automatically can enhance both the site's design and user engagement. To ensure full compatibility with browser requirements, such as Chrome's autoplay policy, it's often necessary to start your videos muted...

How to Add the Post Status in Divi's Dynamic Content

Divi's Dynamic Content feature is great for enhancing your post/page templates with post-specific information. While Divi includes an option to show information such as the Post Created Date using Dynamic Content, there is no equivalent option for the Post Status....

Random Divi Posts