Shopify themes, liquid, logos, and UX
We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more
Hi,
I would like to only display the announcement bar on my home page: https://houseofpapaya.com/
I am using the broadcast theme and I have tried what was suggested here: https://community.shopify.com/c/shopify-design/make-announcement-bar-to-be-visible-only-on-homepage/...
but it isn't working. I also don't have the words announcement in my theme liquid
Hello @Lola
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
{% if template == 'index' %}
<style>
.announcement-bar {
display: block !important;
}
</style>
{% endif %}
<style>
.announcement-bar {
display: none !important;
}
</style>
my reply helpful? Click Like to let me know!
your question answered? Mark it as an Accepted Solution.
this does not work 🙂
Hi i do not have this option 🙂
Hi @Lola
Would you mind sharing your store URL? Thanks!
Yes sorry the domain name hasn't been transfered yet https://22d12c-6a.myshopify.com/?_ab=0&_fd=0&_sc=1
It okay, preview can work with password. Thanks!
https://s2gis5hvsukusrge-81747378511.shopifypreview.com
here is a shareable link that works for two days
Thanks for the info, check this one.
From your Shopify admin dashboard, click on "Online Store" and then "Themes"
Find the theme that you want to edit and click on "Actions" and then "Edit code".
In the "theme. Liquid" file. Find the </body> tag and paste the code below before the tag.
{% if template.name == 'index' %}
<style>
.announcement-bar {
display: block;
}
</style>
{% else %}
<style>
.announcement-bar {
display: none;
}
</style>
{% endif %}
And Save.
Please don't forget to Like and Mark Solution to the post that helped you. Thanks!
Hi,
There is no </body> but I've found one body mentioned:
</head>
<body id="{{ page_title | handle }}" class="template-{{ template.name | handle }} grid-{{ settings.grid_style }}{% if customer %} customer-logged-in{% endif %}{% if settings.animations_enable %} aos-initialized{% endif %}{% if settings.product_grid_outline %} has-line-design{% endif %}" data-animations="{{ settings.animations_enable }}">
{%- render 'loading' -%}
<a class="in-page-link visually-hidden skip-link" data-skip-content href="#MainContent">{{ 'general.accessibility.skip_to_content' | t }}</a>
<div class="container" data-site-container>
<div class="header-sections">
{% sections 'group-header' %}
</div>
{% sections 'group-overlay' %}
<!-- CONTENT -->
<main role="main" id="MainContent" class="main-content">
{{ content_for_layout }}
</main>
</div>
I've tried copying your code between </head>
and <body but it didn't work
That wont be possible without the </body> every sinle store have.
This tag is on the very end of the code in your theme.liquid.
This where you paste the code. MAke some space first.
And this should be look like.
And Save.
Please don't forget to Like and Mark Solution to the post that helped you. Thanks!
Hi,
thanks i did find it but the issue still remains when i preview the site
I tried like this:
{%- comment -%}
In order to use your custom javascript file at assets/custom.js
just cut this next line and paste it outside this comment:
<script src="{{ 'custom.js' | asset_url }}" defer="defer"></script>
{%- endcomment -%}
<!-- Paste marketing code or third party scripts below this comment line ============== -->
{% if template.name == 'index' %}
<style>
.announcement-bar {
display: block;
}
</style>
{% else %}
<style>
.announcement-bar {
display: none;
}
</style>
{% endif %}
<!-- And above this comment line ================================================== -->
</body>
</html>
and like this:
{% if template.name == 'index' %}
<style>
.announcement-bar {
display: block;
}
</style>
{% else %}
<style>
.announcement-bar {
display: none;
}
</style>
{% endif %}
{%- comment -%}
In order to use your custom javascript file at assets/custom.js
just cut this next line and paste it outside this comment:
<script src="{{ 'custom.js' | asset_url }}" defer="defer"></script>
{%- endcomment -%}
<!-- Paste marketing code or third party scripts below this comment line ============== -->
<!-- And above this comment line ================================================== -->
</body>
</html>
Hi @Lola, I had the same problem as you with my Broadcast theme, and here's what I did:
announcement-bar {
display: none !important;
}
.template-index announcement-bar {
display: block !important;
}
This should work for hiding the announcement bar on all pages and showing it only on the homepage. It worked for me, so let me know if it works for you too! Cheers ✌️