Changing Wix Site Menu using wix code

Hey Wix Team, Hey Guys,

Is it possible to modify the wix site menu using code?

Use Case:
I have few pages for visitors from USA and few for visitors from China and currently I have all the pages displayed in the main site menu. My idea is to detect the user location from the ip or manually from the user and then hide the unwanted pages for that particular user using code in the site menu. is this possible?

You have to create a custom menu using button

This website will give you a start https://www.salman2301.com/custom-menu-bar

import wixLocation from 'wix-location';

$w.onReady(function () {
	
	let home = wixLocation.baseUrl;
	let pages = ['home', 'about', 'product', 'contact']

	if (wixLocation.path.length > 0) {
		wixLocation.path[0];
		color();
	} else {
		color();
		$w('#home').style.backgroundColor = '#8b0000';
		$w('#home').style.color = 'white'
	}

	function color() {
	for (let i = 0; i < pages.length; i++) {
			if (`/${wixLocation.path[0]}` === $w(`#${pages[i]}`).link) {
				$w(`#${pages[i]}`).style.backgroundColor = '#8b0000';
				$w(`#${pages[i]}`).style.color = 'white'
			} else{
				$w(`#${pages[i]}`).style.color = '#8b0000';
				$w(`#${pages[i]}`).style.backgroundColor = 'white'
			}
		}
	}

});

Then you have to use GEO Location to track the location and hide the button

Hi,
You can use buttons instead of a menu element, link each button to the a page and in the site’s code hide the relevant buttons once you checked for the user’s location.

Good luck :slight_smile:

Hi,
does this button made menu work with mobile version as well?