Jump to content

How to hide sections from certain URLs?

Recommended Posts

Posted

Hey folks. I just found out how to use code to hide particular sections from view in mobile, and this has been super helpful. What I'd like to do next might be a bit more complicated though... Can I use code to remove sections from a specific URL too? 

For example, with my Shop I'd like to make it so I have a categories section displayed for the storefront, but i'd like to remove them from the specific category pages (eg. my Charms, Prints sub-sections). Is there a way to do this? I would usually do a code injection into the header, but since it's the shop it technically doesn't have seperate pages... I've drawn up what i'm looking for incase that was confusing! 

I have the Squarespace IDs extension downloaded btw if that helps.

Many thanks!

Untitled_Artwork 10.png

Posted
2 hours ago, sabercosmos said:

Hey folks. I just found out how to use code to hide particular sections from view in mobile, and this has been super helpful. What I'd like to do next might be a bit more complicated though... Can I use code to remove sections from a specific URL too? 

For example, with my Shop I'd like to make it so I have a categories section displayed for the storefront, but i'd like to remove them from the specific category pages (eg. my Charms, Prints sub-sections). Is there a way to do this? I would usually do a code injection into the header, but since it's the shop it technically doesn't have seperate pages... I've drawn up what i'm looking for incase that was confusing! 

I have the Squarespace IDs extension downloaded btw if that helps.

Many thanks!

Untitled_Artwork 10.png

You can combine using media query Css and target the right section id you want to hide 

@media only screen and (max-width: 767px) {
  section-id {
    display: none;
  }
}

The extension to get right section id: Squarespace ID Finder

How to get section id:  https://recordit.co/Aj9vXw6rfY

BeyondSpace - Squarespace Website Developer

🖼️ Lightbox Studio (Pinch/Zoom images, videos - PDFs Lightbox - ...) </>  🗓️ Delivery Date Picker (Date picker form field)
Gallery block 7.1 workaround </> 🤖 Ask me anything

Posted
1 hour ago, Beyondspace said:

You can combine using media query Css and target the right section id you want to hide 

Thanks! This works, but it hides the section from all the shop sections. Is there a way to reveal it only for one category? Also sorry my original post was a bit unclear- I'd like to do this for both desktop and mobile. 🙂

Website: https://www.sabercosmos.co.uk/

Pass: forum

The section i'd like to have the "Shop by Collection" section in is Shop > All, and i'd like to remove it from the rest (like Shop > Prints and etc)

Posted
On 11/14/2022 at 11:11 PM, sabercosmos said:

Thanks! This works, but it hides the section from all the shop sections. Is there a way to reveal it only for one category? Also sorry my original post was a bit unclear- I'd like to do this for both desktop and mobile. 🙂

Website: https://www.sabercosmos.co.uk/

Pass: forum

The section i'd like to have the "Shop by Collection" section in is Shop > All, and i'd like to remove it from the rest (like Shop > Prints and etc)

Do you still need help on this? Last week I helped a similar case for a member

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)

Posted
On 11/21/2022 at 8:34 AM, tuanphan said:

Do you still need help on this? Last week I helped a similar case for a member

Yes please! Would you mind linking me the post? 🙂

  • 1 year later...
Posted
On 11/28/2023 at 8:38 PM, ianeaf said:

Hi @tuanphan, may you please share the post link? Also looking for this. Thanks!

You can share link to page + Which section you want to hide, we can check easier

I don't remember the code I used, need to check it on new site

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)

  • 2 months later...
  • 3 weeks later...
Posted

I'm trying to do exactly this and wondering if anyone could help me? 

URL: https://www.vitriccaiannazzi.com/shop-real
PW: vitricca

I have added a section that has images that correspond + link with the main categories in the shop. They look great on desktop but they take up all the vertical space on mobile. What I would like to do is hide them on every category except the ALL category. I've been trying several different things including hiding the section completely on mobile, but there is a padding issue that I can't seem to fix that causes the shop section to bleed up into the header.

This is the page that I would like to keep the first section visible on mobile https://www.vitriccaiannazzi.com/shop-real

For every other category I would like to hide the first section on mobile. 

 

 

Posted
On 3/13/2024 at 9:27 PM, cami_leisk said:

I'm trying to do exactly this and wondering if anyone could help me? 

URL: https://www.vitriccaiannazzi.com/shop-real
PW: vitricca

I have added a section that has images that correspond + link with the main categories in the shop. They look great on desktop but they take up all the vertical space on mobile. What I would like to do is hide them on every category except the ALL category. I've been trying several different things including hiding the section completely on mobile, but there is a padding issue that I can't seem to fix that causes the shop section to bleed up into the header.

This is the page that I would like to keep the first section visible on mobile https://www.vitriccaiannazzi.com/shop-real

For every other category I would like to hide the first section on mobile. 

 

 

Try this code to Website > Website Tools > Code Injection > Footer

  <script>
if (document.location.pathname.indexOf("/shop-real/wabi-sabi") == 0) {
    document.querySelector('body').classList.add('t-hide')
}
    if (document.location.pathname.indexOf("/shop-real/retro") == 0) {
    document.querySelector('body').classList.add('t-hide')
}
    if (document.location.pathname.indexOf("/shop-real/style") == 0) {
    document.querySelector('body').classList.add('t-hide')
}
    if (document.location.pathname.indexOf("/shop-real/tropical") == 0) {
    document.querySelector('body').classList.add('t-hide')
}
  </script>
<style>
  body.t-hide [data-section-id="65bae2de7e897252a2037ce4"] {
    display: none;
}
  body.t-hide [data-section-id="6524479cc6a84c06b4ee2fc6"] {
    margin-top: 150px;
}
</style>
  

 

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)

  • 2 weeks later...
Posted
On 3/15/2024 at 4:22 AM, tuanphan said:

Try this code to Website > Website Tools > Code Injection > Footer

  <script>
if (document.location.pathname.indexOf("/shop-real/wabi-sabi") == 0) {
    document.querySelector('body').classList.add('t-hide')
}
    if (document.location.pathname.indexOf("/shop-real/retro") == 0) {
    document.querySelector('body').classList.add('t-hide')
}
    if (document.location.pathname.indexOf("/shop-real/style") == 0) {
    document.querySelector('body').classList.add('t-hide')
}
    if (document.location.pathname.indexOf("/shop-real/tropical") == 0) {
    document.querySelector('body').classList.add('t-hide')
}
  </script>
<style>
  body.t-hide [data-section-id="65bae2de7e897252a2037ce4"] {
    display: none;
}
  body.t-hide [data-section-id="6524479cc6a84c06b4ee2fc6"] {
    margin-top: 150px;
}
</style>
  

 

@tuanphan I'm trying to use this code to hide the first 'featured' section on this blog for specific category URLs but it isn't working. What am I doing wrong?

 

<script>
if (document.location.pathname.indexOf("/blog?offset=") == 0) {
    document.querySelector('body').classList.add('t-hide')
}
    if (document.location.pathname.indexOf("/blog/category/Engagement") == 0) {
    document.querySelector('body').classList.add('t-hide')
}
    if (document.location.pathname.indexOf("/blog/category/Elopement") == 0) {
    document.querySelector('body').classList.add('t-hide')
}
    if (document.location.pathname.indexOf("/blog/category/Newborn") == 0) {
    document.querySelector('body').classList.add('t-hide')
}
  </script>
<style>
  body.t-hide [data-section-id="6606cb21ffd5013539385ab2"] {
    display: none!important;
}

</style>

 

website: https://helicon-oval-8wh9.squarespace.com/blog

PW: admin

 

 

 

Posted
On 3/29/2024 at 10:00 PM, E-W said:

@tuanphan I'm trying to use this code to hide the first 'featured' section on this blog for specific category URLs but it isn't working. What am I doing wrong?

 

<script>
if (document.location.pathname.indexOf("/blog?offset=") == 0) {
    document.querySelector('body').classList.add('t-hide')
}
    if (document.location.pathname.indexOf("/blog/category/Engagement") == 0) {
    document.querySelector('body').classList.add('t-hide')
}
    if (document.location.pathname.indexOf("/blog/category/Elopement") == 0) {
    document.querySelector('body').classList.add('t-hide')
}
    if (document.location.pathname.indexOf("/blog/category/Newborn") == 0) {
    document.querySelector('body').classList.add('t-hide')
}
  </script>
<style>
  body.t-hide [data-section-id="6606cb21ffd5013539385ab2"] {
    display: none!important;
}

</style>

 

website: https://helicon-oval-8wh9.squarespace.com/blog

PW: admin

 

 

 

I don't see the code. Have you added it yet?

I tried test code for Engagement from my browsers and it still works

image.png.27e73dd859afd8ae9dd8d54d4b7e123e.png

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)

Posted
22 hours ago, tuanphan said:

I don't see the code. Have you added it yet?

I tried test code for Engagement from my browsers and it still works

image.png.27e73dd859afd8ae9dd8d54d4b7e123e.png

@tuanphan It works I just had the code in the wrong place. Thank you!

Create an account or sign in to comment

You need to be a member in order to leave a comment

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.