[Resolved] Restricting Toolset scripts to specific pages or sections
This thread is resolved. Here is a description of the problem and solution.
Problem:
How to restrict Toolset scripts to specific pages or sections Solution:
you can use the WordPress standard hook "wp_print_scripts" and "wp_print_styles" to dequeue the javascript and css files loaded on frontend.
Thanks for your timely response. We are putting together a site in which we are using types extensively - extrapolating from your very helpful classifieds example site.
However, we were benchmarking site speed, and the homepage of the site, which does not rely at all on toolset plugins, and when we enable toolset plugins, the homepage takes a significant speed hit.
Is there anything you know that I can do about this speed hit?
I have attached screenshots of the GTMetrix report that I am working from.
Well - I think you can use the WordPress standard hook wp_print_scripts and wp_print_styles to dequeue the javascript and css files loaded on frontent .
This hook just runs before the scripts and style links being printed to the page. Used with a late priority it will ensure you are attempting to dequeue them once they have been enqueued. You need to find the unwanted scripts and styles that is loaded on home page and dequeue it accordingly.
Here is a simple example I used to dequeue the pagination script and stylesheet from the front-end:
function remove_unwanted_scripts() {
if ( is_home() ) {
/// add scripts to dequeue
// Remove: /res/js/wpv-pagination-embedded.js
wp_dequeue_script( 'views-pagination-script' );
}
}
add_action( 'wp_print_scripts', 'remove_unwanted_scripts', 100 );
function remove_unwanted_styles() {
if ( is_home() ) {
// add styles to dequeue
// Remove: /res/css/wpv-pagination.css
wp_dequeue_style( 'views-pagination-style' );
// Remove: /common/toolset-forms/css/wpt-jquery-ui/datepicker.css
wp_dequeue_style( 'wptoolset-field-datepicker');
}
}
add_action( 'wp_print_styles', 'remove_unwanted_styles', 100 );
You can adjust the above code as per your requirement.