Hi there, in the past you have give me a piece of js code to execute a function that I’ve needed.
The code is this:
jQuery(document).ready(function($)
{
var hash = window.location.hash.substr(1);
if(hash){
jQuery('[data-vc-grid-filter-value=".'+hash+'"]').trigger('click');
}
});
It works perfectly if it is added in custom Js in x-theme customization options. But putting the code there it can’t be executed when some plugins like Autoptimize are active.
So, I have created a dedicated script and enqueued correctly through my function.php file. See below:
function enqueue_vc_script() {
if (is_page(array('home', 'home-en', 'home-de', 'design-progetti')) ) {
wp_enqueue_script( 'vc-script', get_stylesheet_directory_uri() . '/js/vc-script.js' , array('jquery'), '1.0.0', true );
}
}
add_action( 'wp_enqueue_scripts', 'enqueue_vc_script' );
vc_script.js content reflects the code you have provide to me:
/*Script for Visual Composer post category link*/
jQuery(document).ready(function($)
{
var hash = window.location.hash.substr(1);
if(hash){
jQuery('[data-vc-grid-filter-value=".'+hash+'"]').trigger('click');
}
});
And the script is loaded correctly on the frontend:
So the script is active. But in this way that piece of code doesn’t work at all.
Maybe that code has to be changed to work in a enqueued script?
Let me know, thanks