0

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(); } ?>
2
  • For clarity ... Are you trying to only enqueue JS on a singular (specific) page, or on any "single post page"? And by "single post page" I am assuming you only want the JS loaded when you are viewing that post entry, but not on a blog page that lists all posts. Yes?? Happy to offer advice once I understand these elements of your question. Commented Oct 9, 2019 at 19:22
  • Forgot to ask.... Did you write the plugin? If not, naming it might aid the community in researching a solution for you. If so, can you modify it? If not, can you verify whether or not wp_enqueue_scripts is being use (vs add_action('wp_footer',....))? Commented Oct 9, 2019 at 19:30

1 Answer 1

0

You 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;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.