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 Posts

Hide the Page Title in the Hello Elementor Theme

Hiding the page title in the Hello Elementor theme allows you to create a cleaner and more customized page layout, free from default headings that may not fit your design. This is particularly useful for landing pages or custom content layouts where the default page...

How to Hide a Divi Module When Scrolling Up or Down

In this quick tutorial, I’ll show you how to hide a Divi module when scrolling in a specific direction (up or down), so that the module only shows when you want it to. This is especially useful when using Divi’s Scroll Effects feature and you have a effect you want to...

Fade a Divi Image Module Edge into the Background

Want to create a stylish fade effect on your Divi image module—where one side fades smoothly into the background? With a bit of CSS, you can make any edge (or corner) of the image fade out: top, bottom, left, right, or even diagonally.Fade a Divi Image Module Edge...

Hide the Header and Footer in the Hello Elementor Theme

Removing the default header and footer from your Hello Elementor theme allows for a streamlined and distraction-free website design. This is especially useful when creating unique landing pages, full-width layouts, or custom headers and footers with a page builder. In...

Setting up the Divi Password Box Module

Setting up password protection on a page can help you control access to sensitive or private content in WordPress, allowing only authorized visitors to view certain sections. With the Divi Password Box module, you can replace the plain Divi password form with a fully...

Random Posts