Optimize theme
How to best optimize for Avanam theme?
1. Disable Gutenberg assets: Usually, you only use Gutenberg blocks on blog and post pages. So disable them in the rest pages to improve page loading.
- Open functions.php in your-site/wp-content/themes/themename
- Then add this following code:
function themename_disable_gutenberg_wp_enqueue_scripts() {
if( ! is_singular('post') ) {
wp_dequeue_style('wp-block-library');
wp_dequeue_style('wp-block-library-theme');
wp_dequeue_style('wc-blocks-style');
}
}
add_action('wp_enqueue_scripts','themename_disable_gutenberg_wp_enqueue_scripts', 100);
2. Disable WordPress global style: https://github.com/WordPress/gutenberg/issues/36834
- Open functions.php in your-site/wp-content/themes/themename
- Then add the following code:
function themename_remove_wp_global_styles() {
remove_action( 'wp_enqueue_scripts', 'wp_enqueue_global_styles' );
remove_action( 'wp_body_open', 'wp_global_styles_render_svg_filters' );
}
add_action( 'init', 'themename_remove_wp_global_styles' );