Support » Plugin: Share Buttons by AddThis » Buttons not showing when page includes a shortcode with custom post type loop

  • This really simple shortcode function is stopping the AddThis buttons from showing…

    function mwe_rtr_do_shortcode_2() {
        $args = array(
            'post_type' => 'mwe_rtr', //my custom post type
            'posts_per_page' => -1,
            'order' => 'ASC',
            'order_by' => 'date'
        $loop = new WP_Query( $args );
        //loop through custom post types
        while ( $loop->have_posts() ) : $loop->the_post();
            //do nothing
        return 'Only if the above while loop is removed will the AddThis buttons be shown on any page that uses this [mwe_rtr_2] shortcode!';
    add_shortcode( 'mwe_rtr_2', 'mwe_rtr_do_shortcode_2' );

    It’s the presence of the while loop in my code that is causing the AddThis buttons not to show.

    This seems like a bug with AddThis, so can someone solve or advise?

    Thanks in advance,

    PS – All my plugins are up-to-date and I have set WP_DEBUG to TRUE in wp-config.php, but no clues are outputted as to the problem.

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Contributor Srijith V


    Hi James,

    Can I see the page with the issue? I will have a look at and let you know.

    Plugin Contributor Srijith V


    Hi James,

    Looks like global variable $post has been overridden by your shortcode script.

    Can you try changing the following code in the AddThis plugin.

    File: wp-content/plugins/addthis/addthis_social_widget.php

    Function: addthis_display_social_widget($content, $filtered = true, $below_excerpt = false)

    Line number: 1478


    elseif ( is_page($post->ID) )


    elseif ( is_page($post->ID) || get_query_var(‘page_id’) ).

    Hope this will resolve the issue.

    Hiya Srijith,

    Thanks for your reply.

    That doesn’t work, but when I change that line to…
    elseif ( is_page($post->ID) || get_query_var(‘page_id’) || true )
    …then it does work, but what is the proper solution?

    Also, the social buttons do not show on another page where I use a shortcode. The two pages in question are:


    Can also confirm that my shortcode script doesn’t override $post – see my code snippet, above.

    As mentioned in the comment in my code snippet, it is the presence of the loop that appears to be causing the problem.

    Plugin Contributor Srijith V


    Hi James,

    Your if condition,
    elseif ( is_page($post->ID) || get_query_var(‘page_id’) || true )
    will make it always a true condition, which is not a recommended solution.

    It has worked without that true condition in my localhost.

    Could you please check, Show AddThis on pages has been ticked, in the Advanced Settings page from admin.

    Hiya Srijith,

    Thanks for your reply.

    I know it is not a recommended solution. I just tried it to check the AddThis icons would actually show.

    Incidentally, when I leave the “|| true” clause in, the AddThis icons do not show on this aforementioned page – . However, they do show on this aforementioned page – – but with the number-of-shares values all zero (whereas they were previously all above zero before).

    And, yes, I have gone into AddThis advanced settings and the Pages checkbox is ticked. I have also unticked it, saved, reticked it, saved… but your code change is still not working for me.


    Something has just dawned on me, but I’m not sure if it would/should be an issue…

    The AddThis settings may have been tied to my facebook account, but I came off facebook fairly recently.

    That said, the AddThis icons are showing fine on news posts – e.g., .

    Plugin Contributor Srijith V


    Hi James,

    I checked your page The reason the buttons are not showing is that our javascript is not loaded in the page.

    I am not sure about the reason, but can happen due to a conflict with another plugin or theme.

    A quick fix is to add this to your theme file:

    <script type=”text/javascript” src=”//”></script>

    OK, thanks for the reply.

    I have added that line of code just before my </head> tag in my header.php file.

    The result is that this page – – now shows the AddThis icons.

    But the other page – – still does not show the AddThis icons. And if you look at the source code for this page, you will see that addthis_widget.js script is now called twice for this page.

    Sorry for butting in, but I just came across this. Mobilewebexpert, from the code you shared, it looks like you don’t reset the post data, which would result changing the $post variable. Take a look at wp_reset_postdata and Nested Loops for more information.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Buttons not showing when page includes a shortcode with custom post type loop’ is closed to new replies.