Tell us what you are trying to do?
I'm only using 3 views on my home page and nowhere else on the site. However, all the Toolset CSS files and scripts load on every page. So, I'd like to only enqueue Toolset files only on the home page.
Is there any documentation that you are following?
No, but I did check support articles.
What is the link to your site?
hidden link
Hello,
Yes, you are correct, since Toolset Views plugin is using shortcode to render views, and it doesn't know if the page/post contains a view shortcode when rendering HTML header area, so Toolset Views plugin enqueue some CSS/JS files in all front-end pages/posts.
And we do have a plan to optimize all of the assets(CSS/JS files) loaded by Toolset, this project will be completed maybe one or two months, that means if I provide some custom codes to dequeue those files, the custom codes may not work in the future version of Toolset plugins, so you might consider to wait for the new version of Toolset plugins(with optimize assets loaded by Toolset feature) are released.
Hi Luo,
Thanks for the reply and I'm glad to hear it's on your roadmap. I'd like your custom code to dequeue the files please. I'll add it to my code snippets so I can quickly disable when your update is ready over the next few months. Thanks.
Please try to those codes:
add_action( 'wp_enqueue_scripts', 'ts_dequeue_scripts', 1, 999 );
add_action( 'wp_print_scripts', 'ts_dequeue_scripts', 1, 99 );
add_action( 'wp_print_footer_scripts', 'ts_dequeue_scripts', 1, 99 );
function ts_dequeue_scripts(){
if(is_page(123)){ // replace 123 with the front-page ID
return;
}
wp_dequeue_script( 'wptoolset-field-date' );
wp_dequeue_script( 'views-blocks-frontend' );
wp_dequeue_script( 'toolset-common-es-masonry' );
wp_dequeue_style( 'toolset-common-es' );
wp_deregister_style( 'toolset-common-es' );
wp_dequeue_style( 'toolset_blocks-style-css' );
wp_deregister_style( 'toolset_blocks-style-css' );
wp_dequeue_style( 'views-pagination-style' );
wp_deregister_style( 'views-pagination-style' );
wp_dequeue_style( 'toolset-select2-css' );
wp_deregister_style( 'toolset-select2-css' );
}
You will need to replace 123 with your home page ID.