# Hide Code on Certain Pages Not Working Properly

**URL:** <https://forum.wixstudio.com/t/hide-code-on-certain-pages-not-working-properly/18986>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [May 23, 2019, 5:59pm UTC](https://forum.wixstudio.com/t/hide-code-on-certain-pages-not-working-properly/18986 "2019-05-23T17:59:34Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![suzancreates](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/suzancreates/32/982_2.png) [@suzancreates](https://forum.wixstudio.com/u/suzancreates)\
**Post date:** [May 23, 2019, 5:59pm UTC](https://forum.wixstudio.com/t/hide-code-on-certain-pages-not-working-properly/18986/1 "2019-05-23T17:59:34Z")

</div>

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();

---

<div class="post-metadata">

**Author:** ![givemeawhisky](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/givemeawhisky/32/5383_2.png) [@givemeawhisky](https://forum.wixstudio.com/u/givemeawhisky)\
**Post date:** [May 23, 2019, 8:06pm UTC](https://forum.wixstudio.com/t/hide-code-on-certain-pages-not-working-properly/18986/2 "2019-05-23T20:06:48Z")

</div>

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](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.HiddenMixin.html)  
[https://www.wix.com/corvid/reference/$w.HiddenCollapsedElement.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://support.wix.com/en/article/corvid-tutorial-hiding-an-element-on-certain-pages)  
[https://www.wix.com/corvid/example/hide-and-show-elements](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.

```javascript
$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();

```

```javascript
$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();

```

```javascript
export function setupPage() {
if(wixUsers.currentUser.loggedIn) {
$w("#item1").hide();
$w("#item2").show();
}
else {
$w("#item1").show();
$w("#item2").hide();
}

```

---

<div class="post-metadata">

**Author:** ![J.D](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/j.d/32/7312_2.png) [@J.D](https://forum.wixstudio.com/u/J.D)\
**Post date:** [May 23, 2019, 9:09pm UTC](https://forum.wixstudio.com/t/hide-code-on-certain-pages-not-working-properly/18986/3 "2019-05-23T21:09:11Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![suzancreates](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/suzancreates/32/982_2.png) [@suzancreates](https://forum.wixstudio.com/u/suzancreates)\
**Post date:** [May 23, 2019, 9:09pm UTC](https://forum.wixstudio.com/t/hide-code-on-certain-pages-not-working-properly/18986/4 "2019-05-23T21:09:34Z")

</div>

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();  
});

---

<div class="post-metadata">

**Author:** ![suzancreates](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/suzancreates/32/982_2.png) [@suzancreates](https://forum.wixstudio.com/u/suzancreates)\
**Post date:** [May 23, 2019, 9:11pm UTC](https://forum.wixstudio.com/t/hide-code-on-certain-pages-not-working-properly/18986/5 "2019-05-23T21:11:20Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![J.D](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/j.d/32/7312_2.png) [@J.D](https://forum.wixstudio.com/u/J.D)\
**Post date:** [May 23, 2019, 9:16pm UTC](https://forum.wixstudio.com/t/hide-code-on-certain-pages-not-working-properly/18986/6 "2019-05-23T21:16:42Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![suzancreates](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/suzancreates/32/982_2.png) [@suzancreates](https://forum.wixstudio.com/u/suzancreates)\
**Post date:** [May 23, 2019, 9:21pm UTC](https://forum.wixstudio.com/t/hide-code-on-certain-pages-not-working-properly/18986/7 "2019-05-23T21:21:36Z")

</div>

@jonatandor35 Ok, thank you.

---

<div class="post-metadata">

**Author:** ![suzancreates](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/suzancreates/32/982_2.png) [@suzancreates](https://forum.wixstudio.com/u/suzancreates)\
**Post date:** [May 23, 2019, 9:25pm UTC](https://forum.wixstudio.com/t/hide-code-on-certain-pages-not-working-properly/18986/8 "2019-05-23T21:25:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![J.D](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/j.d/32/7312_2.png) [@J.D](https://forum.wixstudio.com/u/J.D)\
**Post date:** [May 23, 2019, 9:28pm UTC](https://forum.wixstudio.com/t/hide-code-on-certain-pages-not-working-properly/18986/9 "2019-05-23T21:28:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![suzancreates](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/suzancreates/32/982_2.png) [@suzancreates](https://forum.wixstudio.com/u/suzancreates)\
**Post date:** [May 23, 2019, 9:30pm UTC](https://forum.wixstudio.com/t/hide-code-on-certain-pages-not-working-properly/18986/10 "2019-05-23T21:30:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![J.D](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/j.d/32/7312_2.png) [@J.D](https://forum.wixstudio.com/u/J.D)\
**Post date:** [May 23, 2019, 9:35pm UTC](https://forum.wixstudio.com/t/hide-code-on-certain-pages-not-working-properly/18986/11 "2019-05-23T21:35:48Z")

</div>

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