Hide Code on Certain Pages Not Working Properly

Hi!
I’m using the code below to hide elements (a group of text buttons) on certain pages. I have “show on all pages” turned on, and have added the code on the pages where I want it to hide. I found the code here on the Corvid forum. It seems temperamental and works sometimes, but most of the time, not at all. Sometimes it works in Preview mode and as I navigate, it decides to stop working entirely and won’t show the elements at all on any of the pages where it is not hidden. I’ve called Wix for help and they have directed me here. I’ve done a lot of troubleshooting but can not solve this problem and am hoping someone can help me. Thank you!

// Hides the element when the page loads
$w(“#group24”).hide();

Would help if you could post more than just that one line as it doesn’t show us anything else which could be causing your problem!

If you weren’t using the show on all pages option within the editor then you could have simply put it in your site tab and it would apply to your whole site.

As for your hide call, this needs to simply go on the page that you are wanting the group to be hidden on.

Have a look at the support page for the show on all pages option, just to make sure that you haven’t got it anywhere that it shouldn’t be so it doesn’t get disabled.
https://support.wix.com/en/article/showing-an-element-on-all-pages-6533570

Anyways have a look at api reference for both show/hide and collapse/expand.
https://www.wix.com/corvid/reference/$w.HiddenMixin.html
https://www.wix.com/corvid/reference/$w.HiddenCollapsedElement.html

Also, look at Wix tutorial.
https://support.wix.com/en/article/corvid-tutorial-hiding-an-element-on-certain-pages
https://www.wix.com/corvid/example/hide-and-show-elements

I use it on my website and never had any issues with mine not working.

$w.onReady( () => {
if(wixUsers.currentUser.loggedIn) {
$w("#loginbutton").label = "Logout";
$w("#membersareaonlystrip").expand();
$w("#whitegapforfooter").hide();
}
else {
$w("#loginbutton").label = "Login";
$w("#membersareaonlystrip").collapse();
$w("#whitegapforfooter ").show();
$w.onReady(function () {
if(wixWindow.formFactor === "Mobile"){
$w("#mobilelogo").show();
$w("#mobilemenuopen").show();
$w("#mobilemenuclose").show();
}
$w("#mobilemenuopen").onClick( () => {
$w("#myMenuContainer").open();
} )
$w("#mobilemenuclose").onClick( () => {
$w("#myMenuContainer").close();
export function setupPage() {
if(wixUsers.currentUser.loggedIn) {
$w("#item1").hide();
$w("#item2").show();
}
else {
$w("#item1").show();
$w("#item2").hide();
}

You should know that if you hide a global element on one page it may stay hidden on other pages (and vice versa). So you can’t rely on the default state, and you have to explicitly hide and show the elements on the relevant pages (you can do it on the site code panel and save time).

Thank you. I’ve checked those things. This is all I have on the page as far as code goes.

$w.onReady( function () {
//TODO: write your page related code here…
// Hides these elements when the page loads
$w(“#group24”).hide();
});

Interesting… I was thinking that could be the case. But that kind of defeats the purpose of the code, doesn’t it…? Or, would I only need to do this on the pages where I need to hide the elements?

@suzancreates It depends on how many pages you have.
Let’s say you have 100 pages and you want this elements to be hidden on 2 of them.
Then on the site code section (this code runs first) write: show() and in these specific 2 write hide().
But if let’s say you need it to be hidden on 50 pages, then you should create an array of the 50 pages paths and using wixLocation and the JS includes method make them hidden on the site code section.

@jonatandor35 Ok, thank you.

Do I need to write “show” on all the pages where it won’t be hidden?

@suzancreates as I said you can write 1 time show() in the site panel (it’s a global code for all the page).

@jonatandor35 Thanks for your help. I’m new at this, but I’m trying.

@suzancreates you’re welcome. If you have further questions, don’t hesitate, just ask. :slight_smile: