The WPFolks app is out on iPhone and Android. Free, no ads. Download on the App Store Get it on Google Play
Skip to main content
Login Join
Snippet · PHP

Prevent Footer JavaScript from Running in Elementor Editor

Shared by Qevora Software · August 24, 2026 · @wp_footer

60 views
Back to Snippets

This snippet runs custom footer JavaScript on the frontend while preventing it from executing inside the Elementor Editor.

It is useful for footer accordions, toggles, animations, and other jQuery-based scripts that manipulate the page DOM. By detecting the elementor-editor-active class, the script exits early when the Elementor Editor is active, helping prevent unnecessary JavaScript execution and potential editor-side conflicts.

Benefits

1. Elementor Editor Safe
Prevents the custom footer JavaScript from executing while editing a page in Elementor.

2. Reduces JavaScript Conflicts
Helps prevent custom accordion, animation, toggle, or DOM-manipulation scripts from interfering with the Elementor editing interface.

3. Frontend-Only Functionality
The JavaScript runs where it is actually needed—the live website frontend.

4. Useful for jQuery Scripts
Works well with custom jQuery-based footer interactions such as accordions, dropdowns, toggles, and animations.

5. Simple and Lightweight
Uses a straightforward body-class check and does not require an additional plugin or complex configuration.

6. Easy to Customize
You can place your actual footer accordion functionality inside the footerAccordion() function.

<?php
/* Prevent Footer JavaScript from Running in Elementor Editor */

function footer_accordion_script() {
	?>
	<script>
	jQuery(function ($) {

		// Do not run inside the Elementor Editor.
		if ($('body').hasClass('elementor-editor-active')) {
			return;
		}

		function footerAccordion() {
			// Add your footer accordion code here.
		}

		footerAccordion();
	});
	</script>
	<?php
}
add_action( 'wp_footer', 'footer_accordion_script', 100 );
Know a different way to do this? Add your approach as a variation so folks can compare them side by side.
Submit a variation

1 comment

  1. Amit Dholiya
    Amit Dholiya @amitdholiya

    This is used to run custom footer JavaScript only on the frontend and skip it inside the Elementor Editor. The elementor-editor-active class check is a simple way to avoid script conflicts while editing, and it works well for footer accordions and toggles.

    Report

Proudly supported by