Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author micropat

    (@micropat)

    Yes, you can add the following PHP code using a “functionality” plugin such as the Code Snippets plugin (or your own functions.php file):

    // Make AddToAny standard share buttons appear above my related posts
    function addtoany_before_my_related_posts( $query ) {
        remove_filter( 'the_content', 'A2A_SHARE_SAVE_add_to_content', 98 );
        
        if ( $query->is_main_query() && is_singular() ) {
            add_filter( 'the_content', 'A2A_SHARE_SAVE_add_to_content', 39 );
        }
    }
    add_action( 'pre_get_posts', 'addtoany_before_my_related_posts' );

    Adjust the 39 priority number in the code as needed to make the buttons appear earlier or later.

    Thread Starter agg2

    (@agg2)

    @micropat It’s a bit difficult in the case of a WooCommerce installation as it may not be behaving as you expect. Additionally, I use custom priority orderings for other content.

    For posts, with any priority from 0 to 999, the share button positioning remains unchanged.

    I noticed that checking “Display at the top of Products” option causes the share buttons to display once in the product short description and again in long description.
    How can I change the order of display for each of those independently?

    If you need access to a test website to answer this problem, I can email you login details if you provide your email.

    Plugin Author micropat

    (@micropat)

    The default “bottom” option gives you more control than the “top” option. The top option will always try to prepend content.

    In the case of WooCommerce Products, specifically, AddToAny hooks to woocommerce_share, so look into rearranging the woocommerce_share part of your theme if you need to adjust AddToAny’s placement among other short description components.

    Thread Starter agg2

    (@agg2)

    I’m still struggling to make it do what I want.

    In the post instance I want to force the addshare buttons to appear above the featured image, and then again at the end of the post.

    In the product page instance, I want to remove the share buttons from the long description and reposition the share buttons in the short description to appear underneath the title.

    Can you please suggest explicit code, as I’m confused about what is hooking to what exactly.

    • This reply was modified 6 years, 11 months ago by agg2.
    Plugin Author micropat

    (@micropat)

    Set Placement to ‘Top & Bottom’ — this applies to all post types.

    Then hide the buttons in the long description of WooCommerce Products with some Additional CSS:

    body.single-product .addtoany_content { display: none; }

    You’ll want to check with WooCommerce on how to best move their woocommerce_template_single_sharing hook in your Storefront theme.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Change priority order of hook for share buttons’ is closed to new replies.