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.