Loading plugin script only on required page?

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

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
  • 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. – Mike Baxter 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',....))? – Mike Baxter Commented Oct 9, 2019 at 19:30
Add a comment  | 

1 Answer 1

Reset to default 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;
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745094056a4610866.html

相关推荐

  • Loading plugin script only on required page?

    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

    16小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信