Skip to content

Instantly share code, notes, and snippets.

@mototeam
Created April 8, 2020 14:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mototeam/34b4ef0cb4f4ff4ff4d3c8a5f9a5cafe to your computer and use it in GitHub Desktop.
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.
<?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