• Resolved magmachamber

    (@magmachamber)


    Hi. I have a site where it only makes sense to share my homepage. I barely tweaked your example that shows you how to modify the share event and it works great:

    a2a_config.callbacks.push({
        share: function(share_data) {
                // The shared URL
            var old_url = share_data.url;
            // Initialize new shared URL
            var new_url = 'http://www.mysite.com';
    
            // Modify the share by returning an object
            // with a "url" property containing the new URL
            if (new_url != old_url) {
                return {
                    url: new_url
                };
            }
        }
    });

    However I think it pulls the share count before this function is invoked, because the number shown is the number it would have been had I not done this. Is there any way to work around this? THANKS for this great free plugin!

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

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter magmachamber

    (@magmachamber)

    Actually now I see that Pinterest doesn’t seem to work with this method. Is there an easier way to do this that I am just overlooking? Thanks.

    Plugin Author micropat

    (@micropat)

    Check out “How can I place the share buttons in a specific area of my site?” in the plugin FAQs.

    If you want to customize the shared URL and title, use the following code as a template:

    <?php if ( function_exists( 'ADDTOANY_SHARE_SAVE_KIT' ) ) {
        ADDTOANY_SHARE_SAVE_KIT( array( 'linkname' => 'Example Page', 'linkurl' => 'https://example.com/page.html' ) );
    } ?>

    Thread Starter magmachamber

    (@magmachamber)

    Thank you. This ended up being a bit more than I bargained for, fiddling in my theme’s numerous convoluted php files. I just scrapped the floating buttons altogether and went with this shortcode on every page and post:

    [addtoany url="http://myhomepage.com" title="My homepage"]

    It works. However I did notice that it seems Pinterest won’t display correct share counts unless you are actually on the page in the url field. I tried changing the url in the shortcode to:

    http://www.myhomepage.com
    http://www.myhomepage.com/
    http://myhomepage.com/

    I just turned the share count for Pinterest off. No big deal, strange though. Thanks for the help.

    Thread Starter magmachamber

    (@magmachamber)

    Forgive me for dragging this out. I see the reason Pinterest share counts are off is because despite setting a url variable in the shortcode, it appears that Pinterest ignores this and shares whatever page you are actually on. Is this something you might be able to send me a pointer on?

    🙂

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Custom URL with event handling’ is closed to new replies.