I have a plugin that is loading its .js on every page on my site.
I was able to filter out the plugin from loading, but i can't figure out how to specify the pages on which to load.
Plugin Code:
function A2A_SHARE_SAVE_head_script() {
add_filter( 'addtoany_script_disabled', '__return_true' );
$script_disabled = apply_filters( 'addtoany_script_disabled', false );
I need to be able to en queue the script on blog single post pages, the page template looks like this:
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'entry' ); ?>
<?php endwhile; endif; ?>
And then in entry.php i manually call the plugin as follows:
<?php if ( function_exists( 'social_sharing_buttons' ) ) { social_sharing_buttons(); } ?>
I have a plugin that is loading its .js on every page on my site.
I was able to filter out the plugin from loading, but i can't figure out how to specify the pages on which to load.
Plugin Code:
function A2A_SHARE_SAVE_head_script() {
add_filter( 'addtoany_script_disabled', '__return_true' );
$script_disabled = apply_filters( 'addtoany_script_disabled', false );
I need to be able to en queue the script on blog single post pages, the page template looks like this:
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'entry' ); ?>
<?php endwhile; endif; ?>
And then in entry.php i manually call the plugin as follows:
<?php if ( function_exists( 'social_sharing_buttons' ) ) { social_sharing_buttons(); } ?>
Share
Improve this question
asked Oct 9, 2019 at 14:32
DDullaDDulla
1112 bronze badges
2
|
1 Answer
Reset to default 0You could try this, it should disable the script from loading on anything other than single blog post pages without having to edit your templates:
add_filter('addtoany_script_disabled', 'disable_a2a_script_except_on_posts');
function disable_a2a_script_except_on_posts($disabled) {
if (!is_single()) {$disabled = true;}
return $disabled;
}
add_action('wp_footer',....)
)? – Mike Baxter Commented Oct 9, 2019 at 19:30