Link a post grid category (update)

Hi there, please reference to this post Link a post grid category

After latests updates, this solution doesn’t work anymore. Maybe the JS code is not valid anymore. Can your help me adjust this solution to have the desired behavior?

Thanks a lot

Hi Alessandro,

Thanks for reaching out.
The sample code in the reference thread is working fine, but the data-vc-grid-filter-value attribute values are changed for custom post grid in comparison to the previous one.
You need to add the same following code into the Theme Options > JS.

jQuery(document).ready(function($) 
{
    var hash = window.location.hash.substr(1);
    if(hash){
        jQuery('[data-vc-grid-filter-value=".'+hash+'"]').trigger('click');
    }
});

And the link should be like :

  1. https://www.zadrainterni.it/design-progetti/#vc_grid-term-100
  2. https://www.zadrainterni.it/design-progetti/#vc_grid-term-112
  3. https://www.zadrainterni.it/design-progetti/#vc_grid-term-116

You can find the attribute values by inspecting the element through the browser debugger.

Hope it helps.
Thanks

Ok thanks, it works. But I have found what is the real problem: Autoptimize plugin. When it’s activated, the link doesn’t take to the right destination anymore.

Can I do something inside plugin settings to avoid this behavior?

Thanks

Hi Alessandro,

Great that it works. The issue might be with the minification of the JavaScript code using the Autoptimize plugin, you can deselect the option to optimize the JavaScript from the plugin settings.

Thanks

Ok, but I would like tu use optimization for JS code. Is there a way to intervene only for that js?

Hi Alessandro,

You can add that specific JavaScript code into a different .js file and exclude that file to be optimized from the settings of the plugin. To include the external script file, you may need to know how that can be included, please find the following article on that.

  1. https://premium.wpmudev.org/blog/adding-scripts-and-styles-wordpress-enqueueing/
  2. https://www.wpbeginner.com/wp-tutorials/how-to-properly-add-javascripts-and-styles-in-wordpress/

Hope it helps.
Thanks

Ok thank you, I’ll try.

Hi Alessandro,

You are most welcome.

Thanks

Hi, I have enqueued the script in my functions.php. I see the script loaded in frontend, but it doesn’t work.

This is the code to enqueue the script:

  `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', false );
    }
        }`

Have you some suggestion?

Thanks

Hi Alessandro,

I guess you didn’t exclude the custom js file in your autoptimize plugin. Please put the js code file on the Exclude scripts from Autoptimize and let us know how it goes.

Hope that helps.

Thank you.

Hi there, yes I have already excluded the script from Autoptimize.

I have also try to exclude script inserting only the file name, but it doesn’t work.

Have you some idea?
Thanks

Ok, I have verified that the script doesn’t work also with Autoptimize plugin disabled. So, I think enqueueing the script it’s not a valid alternative or it has to be executed in another way.

Any idea?

Thanks

Hi Alessandro,

To investigate the cause of the issue we need to log into your website, can you please provide login credentials for your site in a secure note, including:

– WordPress Site URL & Login URL
– WordPress Admin username/password

To create a secure note, click the key icon underneath any of your posts.

Thanks

Ok

Let me know, thanks

Hey Alessandro,

Thank you for providing the credentials, I checked your page link from the previous post that has the links but it seems like it doesn’t exist anymore.

Please note that the code you’re using serves as a guide only and is to help you in getting started so implementing it and maintaining the code will be out of our support scope and for further maintenance for new possible versions of the theme that may cause the customization to break, you will need to hire a developer.

Thank you for your understanding!

Hi, thank you. It’s strange that the link doesn’t exist, I can see the site and the login page without any problem. Can you visit the website?

Hello Alessandro,

Thanks for updating in! I have logged in and I found out that most of your plugins are outdated. Have it updated first and then you may need to check the site again. To be sure that the JS code is still working, kindly temporarily disable the Autoptimize and any other caching plugin before testing the plugin.

Kindly let us know how it goes.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.