WordPress.org

Forums

AddToAny Share Buttons
[resolved] Remove AddToAny javascript code if not needed (5 posts)

  1. mensmaximus
    Member
    Posted 2 years ago #

    Although you can disable AddToAny to be displayed on pages the Javascript code is still loaded on pages. To reduce code and to speed up page load it would be better to not load the Javascript code if it is not needed. I guess many users would appreciate this feature in an upcoming release of AddToAny.

    In addition to allow the usage of AddToAny in Europe to be compliant to the EU e-Privacy Directive it would be useful to introduce a new parameter to the additional options to prevent AddToAny from loading until a cookie has been set. The name of the cookie should be the value of the new parameter. This way administrators could use any of the existing WordPress cookie plugins. I would love to see something like

    a2a_config.cookieinit = 'name_of_the_cookie_needed_to_load_a2a'

    Kind regards

    Michael

    https://wordpress.org/plugins/add-to-any/

  2. mensmaximus
    Member
    Posted 2 years ago #

    I forgot to mention I solved the first issue (javascript code loading although display on pages is disabled) by altering the following functions in add-to-any.php:

    A2A_SHARE_SAVE_footer_script()
    A2A_SHARE_SAVE_head_script()

    I put this code below the is_admin if-statement in both functions:

    $options = get_option( 'addtoany_options' );
    if ( $options['display_in_pages'] != '1' && is_page () )
        return;
  3. micropat
    Member
    Plugin Author

    Posted 2 years ago #

    Thanks for your feedback, Michael! These are good requests that will be considered in future releases. Some color:

    The plugin currently loads the script [asynchronously] for most requests so that AddToAny can be reliably loaded from AJAX (widgets, infinite scrolls, etc.).

    To support your use-case most immediately I think it'd be interesting to make the script functions modifiable by filters, so you can disable the script programmatically (probably in your functions.php) without having to modify the plugin itself. How does that sound?

  4. mensmaximus
    Member
    Posted 2 years ago #

    It would be perfect to have a hook to enable/disable the script programmatically.

  5. micropat
    Member
    Plugin Author

    Posted 2 years ago #

    The addtoany_script_disabled hook was added in version 1.3.2.

    Example usage:
    add_filter( 'addtoany_script_disabled', '__return_true' );

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • AddToAny Share Buttons
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic