Newsletter pop-up keeps reappearing every time I change pages, even after I’ve closed it

Topic summary

A newsletter popup is reappearing on every page navigation despite being closed by the user. The root cause is a JavaScript selector mismatch in the theme.liquid file.

The Problem:

  • The JavaScript targets .popup-newsletter and .close-popup classes
  • The actual HTML uses .newsletter-popup and [data-popup-close] attributes
  • This mismatch prevents the close state from being saved to localStorage

The Solution:
Update the JavaScript selectors to match the actual HTML structure:

  • Change document.querySelector('.popup-newsletter') to document.querySelector('.newsletter-popup')
  • Change popup?.querySelector('.close-popup') to popup?.querySelector('[data-popup-close]')

A complete corrected script was provided that properly saves the popup’s closed state to localStorage and prevents it from reappearing. The fix also requires appropriate CSS (.newsletter-popup.is-visible { display: block; }) to work with the classList toggle approach.

Status: Solution provided, awaiting confirmation from the original poster.

Summarized with AI on October 28. AI used: claude-sonnet-4-5-20250929.

Hi, this is the code from my pop up and my theme.liquid if it helps!

and this is the code from my theme.liquid:

{% if current_tags %}{% assign meta_tags = current_tags | join: ', ’ %}{% endif %}

{% if template contains "index" %} {{ page_title }} {% else %} {{ page_title }} {% if current_tags %} {{ 'general.meta.tagged_html' | t: tags: meta_tags }}{% endif %} {% if current_page != 1 %} {{ 'general.meta.page' | t: page_number: current_page }}{% endif %} {% unless page_title contains shop.name %} - {{ shop.name }}{% endunless %} {% endif %}

{% if page_description %}

{% endif %}

{% render ‘social-meta-info’ %}

{% if collection.previous_product %}

{% endif %} {% if collection.next_product %} {% endif %}

{{ ‘theme.css’ | asset_url | stylesheet_tag }}

{% if settings.favicon != nil %}

{% else %} {% endif %}

{% if template contains ‘customer’ %}

{% endif %}

{% if settings.show_shipping_calculator %}

{% endif %}

{{ content_for_header }}

.collapsible-content { display: none; } .collapsible-description details summary { cursor: pointer; }
{% render 'age-gate', id: 'page', sections: content_for_layout %}

{{ ‘general.accessibility.skip_to_content’ | t }}

{% comment %}Icon star SVG{% endcomment %}








{% section ‘header’ %}

{{ content_for_layout }}

{% section ‘footer’ %}
{% if settings.newsletter_popup %}{% render ‘newsletter-popup’ %}{% endif %}
{% if settings.size_chart != blank and template contains ‘product’ %}{% render ‘size-chart-popup’ %}{% endif %}
{% render ‘modal’ %}
{% render ‘gallery-modal’ %}
{% render ‘predictive-search’ %}
{% if settings.cart_action == ‘ajax’ %}{% render ‘cart-drawer’ %}{% endif %}

Hi @IvoireSkincare ,

I am from Mageplaza - Shopify solution expert.

Your JavaScript is targeting the wrong popup class, so the close state is never saved properly.

Specific issue:
In your JavaScript code (at the end of theme.liquid), you have:

const popup = document.querySelector('.popup-newsletter');
const closeBtn = popup?.querySelector('.close-popup');

But in your actual HTML for the popup, you wrote:


So:

- .popup-newsletter doesn’t exist -> popup is null
- As a result, the script does nothing, the popup is never hidden, and the closed state is never saved.

You just need to update the selectors to match the actual class names. Specifically, change this:

```javascript
const popup = document.querySelector('.newsletter-popup');
const closeBtn = popup?.querySelector('[data-popup-close]');

Updated working script:


Make sure you have CSS like .newsletter-popup.is-visible { display: block; } if you’re using classList.add.

Please let me know if it works as expected!

Best regards!