How can I remove duplicate links in a mobile menu using CSS?

Solved

How can I remove duplicate links in a mobile menu using CSS?

biznazz101
Shopify Partner
494 50 97

Hello, I am building a store using the "Fresh" theme. The navigation menu looks fine on desktop/tablet but on mobile the menu drawer displays all the links twice. (I am guessing it is due to the topbar menu part of the header)

Is there a way to hide or remove these using CSS without effecting the normal header menu?
Here is the link:
https://hziz8w30dfq0hksl-85943648529.shopifypreview.com

Desktop:

biznazz101_0-1711127039434.png


Mobile:

biznazz101_1-1711127118744.png

Thanks for the help everyone!

 

Don't hesitate to reach out for more help with your store.
SEE OUR TASK STORE or check us out via our profile! FREE STORE AUDIT
Accepted Solution (1)

BrewBrains
Shopify Partner
160 26 33

This is an accepted solution.

Hi @biznazz101 ,

 

You can add code by following these steps

1. Go to Online Store -> Theme -> Edit code.
2. Open your theme.liquid file
3. Paste the below code before </body> on theme.liquid

 

 

<script>
const menuItems = document.querySelectorAll('#mobile-menu--main-menu li');
let uniqueItems = [];
menuItems.forEach(item => {
    const text = item.textContent.trim(); 
    if (text !== '' && !uniqueItems.includes(text)) {
        uniqueItems.push(text); 
    } else {
        item.style.display = 'none'; 
    }
});
</script>

 

 

 

 

Screenshot 2024-03-23 at 1.30.42 PM.png

Was my reply helpful? Click Like to let me know!

Was your question answered? Mark it as an Accepted Solution.

Was I helpful?

Buy me a coffee


Sandesh Paudyal |

| Shopify Developer


Need help with your store?

 sandeshpaudyal99@gmail.com

For quick response - Message Me : +9779851353732

View solution in original post

Reply 1 (1)

BrewBrains
Shopify Partner
160 26 33

This is an accepted solution.

Hi @biznazz101 ,

 

You can add code by following these steps

1. Go to Online Store -> Theme -> Edit code.
2. Open your theme.liquid file
3. Paste the below code before </body> on theme.liquid

 

 

<script>
const menuItems = document.querySelectorAll('#mobile-menu--main-menu li');
let uniqueItems = [];
menuItems.forEach(item => {
    const text = item.textContent.trim(); 
    if (text !== '' && !uniqueItems.includes(text)) {
        uniqueItems.push(text); 
    } else {
        item.style.display = 'none'; 
    }
});
</script>

 

 

 

 

Screenshot 2024-03-23 at 1.30.42 PM.png

Was my reply helpful? Click Like to let me know!

Was your question answered? Mark it as an Accepted Solution.

Was I helpful?

Buy me a coffee


Sandesh Paudyal |

| Shopify Developer


Need help with your store?

 sandeshpaudyal99@gmail.com

For quick response - Message Me : +9779851353732