Created
January 27, 2021 20:08
-
-
Save sabrina-zeidan/4122f2d6c01781788cd77f2aab9a4f1a to your computer and use it in GitHub Desktop.
Optimize Add2Any loading it's styles and scripts
This file contains 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
//This filters display, but CSS and JS are still loaded | |
add_filter( 'addtoany_script_disabled', 'addtoany_disable_display' ); | |
function addtoany_disable_display($script_disabled) { | |
if ( is_front_page() || is_archive() ) { | |
return true; | |
} else { | |
return $script_disabled; | |
} | |
} | |
//Prevent Add2Any CSS from being loaded | |
add_action( 'wp_print_styles','a2a_optimize_styles', 10 ); | |
function a2a_optimize_styles() { | |
if ( is_front_page() || is_archive() ) { | |
wp_dequeue_style('addtoany-inline'); | |
wp_dequeue_style('addtoany'); | |
} | |
} | |
//Prevent Add2Any JS from being loaded | |
add_action('wp_enqueue_scripts','a2a_optimize_scripts'); | |
function a2a_optimize_scripts($hook) { | |
if ( is_front_page() || is_archive() ) { | |
wp_dequeue_script('addtoany'); | |
wp_deregister_script('addtoany'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment