Site logo

Archived topic

CTA button on menu item

13 replies · Started by Lynn on August 24, 2021

Viewing posts 1–14 of 14

Hi there,
I used the css code on the following page - https://docs.generatepress.com/article/adding-buttons-navigation/ to add a button to one of the menu items in my primary navigation. It worked great. However, when I added sub menus to that menu item, a CTA button got added to each of the sub-menu items (please see http://www.arnpriorhumanesociety.ca/new-website/). I don't want this. How can I have a button just on the parent item?

Thanks in advance for your advice.

Lynn

Hi there,

Edit your CSS selector to this:
.main-navigation .main-nav ul > li.nav-button > a

Thanks Leo. That works great.

No problem :)

Hi there,

for that button it would be easier to not use the CSS method.

Instead;

1. Create a New Block Element in Appearance > Elements:

https://docs.generatepress.com/article/block-element-hook/

2. Add your GB Button to the block editor.

2.1 With the Buttons block selected, in Advanced > Additional CSS Class(es) you can use the GP hide-on-* classes if you wish to hide the button on different devices:

https://docs.generatepress.com/article/responsive-display/#using-our-hide-on-classes

3. Set the Hook to menu_bar_items

4. Set the Display Rules.

This way you can style the button exactly the same way as your other button

that works. thx

How can we add the same CTA into the mobile menu ?

thx

Do you want it to show along with the hamburger icon or do you want it to show with the other menu items by clicking the hamburger icon on mobile?

to show with the other menu items by clicking the hamburger icon on mobile

thx Ying

It's because the 2 buttons blocks are using the same ID.

GB generates CSS (style) based on IDs, when the 2 blocks are sharing the same ID, their style will override each other.

The solution is easy, go to the hero section, select the buttons block, duplicate it and delete the original one.

The difference between duplicate and copy/paste is that duplicate generates a new set of ID for the new blocks, while copy/paste doesn't.

Hope that's clear :)

thx

No problem :)

This archived topic is closed to new replies.