Copied!
It's on your clipboard.
You’ve been offline for 0 second. Please check your Internet connection.

Help Us Improve

Found an issue or have an idea? Let us know.
Select all that apply...
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
Show Empty State When Loop Has No Posts
Preview
Download Template
Report Bug

Info

Resource
CMS
Builder
Elementor
Add-ons
Elementor Pro
Last Updated
Jan 8, 2026

Overview

By default, Elementor doesn’t give you much control over what happens when a Loop widget has no posts. You’re stuck with the basic “nothing found” message and that’s it.

This snippet fills that gap.

It lets you design your own custom empty state using the Elementor editor and place it anywhere below the Loop widget. When the loop has no posts, whether on page load or after using taxonomy or filter widgets, the Loop widget is automatically hidden and your custom empty state is shown instead.

The snippet simply watches for built-in empty-state marker, the .e-loop-nothing-found-message class, which Elementor outputs whenever a Loop widget has no posts.

On the live site, the empty state only appears when it’s actually needed. Inside the Elementor editor, the logic is turned off, so nothing gets hidden while you’re designing.

Features

Setup

01
Add External Scripts

Copy & paste the scripts before the </body> tag of your project. If you added them before for another setup, skip this step.

Language
Copy
01
Copy structure to Elementor

Right-click in Elementor, choose “Paste from another site,” and while the popup is open, press cmd/ctrl + v to insert the layout.

Copy To Elementor
01
Add HTML

Place the code in an HTML widget or add it through Elementor → Custom Code (before the closing </body> tag) either globally or only on selected pages.

Language
Copy
01
Add custom CSS

Paste the code through the page or site settings, or add it via Elementor → Custom Code (before </body>) for broader use.

Language
Copy
body:not(.elementor-editor-active)
[ou-loop-hide-empty]:has(.e-loop-nothing-found-message) {
  display: none !important;
}

body:not(.elementor-editor-active)
[ou-loop-empty-state] {
  display: none;
}
01
Add custom Javascript

Paste the script through Elementor → Custom Code (set to load after </body>) for site-wide or page-specific loading.

Language
Copy
document.addEventListener("DOMContentLoaded", () => {
  if (document.body.classList.contains("elementor-editor-active")) return;

  const loops = document.querySelectorAll("[ou-loop-hide-empty]");
  const emptyStates = document.querySelectorAll("[ou-loop-empty-state]");

  const updateState = () => {
    loops.forEach(loop => {
      const isEmpty = loop.querySelector(".e-loop-nothing-found-message");

      emptyStates.forEach(state => {
        if (isEmpty) {
          state.classList.add("ou-loop-empty-visible");
        } else {
          state.classList.remove("ou-loop-empty-visible");
        }
      });
    });
  };

  updateState();

  const observer = new MutationObserver(updateState);

  loops.forEach(loop => {
    observer.observe(loop, {
      childList: true,
      subtree: true
    });
  });
});
01
Add custom PHP

Place the PHP snippet inside your theme’s functions.php or using any code snippet to enable logic.

Language
Copy
01

Add Attribute

Add the attribute ou-loop-hide-empty to the Loop widget itself. This controls hiding the Loop widget when it has no posts.

Add the attribute ou-loop-empty-state to the element you want to show as the empty state. This element remains hidden by default.

01
Publish and preview live
Some solutions only work on the live site. Always publish and test after each change, as results may not appear in the editor.

Implementation