Snippets: 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() { ?>
	<script>
		( 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 ) );
	</script>
<?php } );

Snippet Type: PHP

All PHP snippets should be added via a child theme's functions.php file or via the Code Snippets Plugin (or alternative plugin)