Skip to content

Snippet: Open Accordion When Clicking Menu Link

The following script will allow you to open any accordion tab when clicking on a menu item simply by using the "open-accordion" classname on the menu item. Your menu item link should have the format "site.com/#accordion-ID" for it to work correctly.

add_action( 'wp_footer', function() { ?>
	
		( function( $ ) {
			'use strict';
			$( '.open-accordion a' ).click( function() {
				var href = $( this ).attr( 'href' );
				var hash = href.substr( href.indexOf( '#' ) );
				var $target = $( hash ).find( '.vc_tta-panel-title > a' );
				$target.click();
			} );
		} ( jQuery ) );
	
<?php } );
All PHP snippets should be added via child theme's functions.php file or via a plugin. We recommend Code Snippets (100% Free) or WPCode (sponsored)
Back To Top