Created
April 8, 2020 14:49
-
-
Save mototeam/34b4ef0cb4f4ff4ff4d3c8a5f9a5cafe to your computer and use it in GitHub Desktop.
An example of how to prevent all or specific styles from loading on the pages of your WordPress blog.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* The code below removes the loading of some assets | |
* needed for the Getwid blocks on frontend | |
* | |
* Uncomment the element of the array that you want | |
* to prevent from loading | |
*/ | |
add_filter( 'getwid/blocks_style_css/dependencies', 'my_theme_dequeue_getwid_styles', 99 ); | |
function my_theme_dequeue_getwid_styles( $styles ) { | |
$styles_to_remove = [ | |
// 0 => 'magnific-popup', | |
// 1 => 'slick', | |
// 2 => 'slick-theme', | |
// 3 => 'fontawesome-free' | |
]; | |
$styles = array_diff( $styles, $styles_to_remove ); | |
return $styles; | |
}; | |
/** | |
* The code below removes the loading of all assets | |
* needed for the Getwid blocks on frontend | |
*/ | |
add_action( 'init', 'my_theme_remove_all_getwid_styles' ); | |
function my_theme_remove_all_getwid_styles() { | |
remove_action( 'enqueue_block_assets', [ \Getwid\ScriptsManager::getInstance(), 'enqueueFrontBlockAssets' ] ); | |
} | |
/** | |
* | |
* For example, if you want to remove all Getwid assets | |
* that are loaded on: | |
* blog page, | |
* page with specific ID, | |
* specific page template | |
* | |
* */ | |
add_action( 'template_redirect', 'my_theme_remove_all_getwid_styles_on_pages' ); | |
function my_theme_remove_all_getwid_styles_on_pages() { | |
$should_dequeue_styles = is_home() || | |
1253 == get_the_ID() || | |
is_page_template( 'my-theme-custom-template.php' ); | |
if ( $should_dequeue_styles ) { | |
remove_action( 'enqueue_block_assets', [ \Getwid\ScriptsManager::getInstance(), 'enqueueFrontBlockAssets' ] ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment