skip to Main Content

Disable WPBakery Accordion URL Hash Change

You may want to consider using the Themes "Toggle" and "Toggle Group" elements instead of the WPBakery Accordion which are much cleaner and modern.

By default when using the WPBakery Accordion element whenever you click on a new item it will change the URL in the browser, the following snippet removes that functionality and prevents the URL hash change.

/**
 * Disables the WPBakery Accordion element URL hash change.
 *
 * @link https://total.wpexplorer.com/docs/snippets/disable-wpbakery-accordion-url-hash-change/
 */
add_action( 'wp_footer', function() {
?>
	<script>
	jQuery( function() {
		if ( jQuery.fn.vcAccordion && jQuery.fn.vcAccordion.Constructor) {
			jQuery.fn.vcAccordion.Constructor.prototype.changeLocationHash = function() {};
		}
	} );
	</script>
<?php
}, PHP_INT_MAX );
All PHP snippets should be added via child theme's functions.php file or via the Code Snippets Plugin (or alternative plugin)
Back To Top