Pat from AddToAny was kind enough to comment on my previous post about getting Yourls and AddToAny work together. He offered a better approach that effectively removes the “via @AddToAny” attribution and keeps my own short urls intact on links shared through their service.
Here’s how to do it:
From the WordPress administration panel, go to Settings > Share/Save Buttons and in the “Additional Options” box, paste the following:
a2a_track_links='custom';
a2a_track_links_key = my_yourl;
The variable a2a_track_links_key is a placeholder for the URL you want shared. By default AddToAny will just take the current page’s location.href if you don’t set this key manually. Since everything in the “Additional Options” box is JavaScript (not PHP) we can’t just print the call to wp_ozh_yourls_geturl in order to get the short url for the current post. We have to use a placeholder variable called “my_yourl” which we’ll define with the short URL from within the blog post template itself (which is in PHP and can call wp_ozh_yourls_geturl).
In your theme’s single.php file, place this bit of JavaScript code right below the <?php get_header(); ?> call:
<script type="text/javascript"> var my_yourl = "<?php echo wp_ozh_yourls_geturl($post->ID); ?>"; </script>
Now, a2a_track_links_key is set to the short URL for the post on the current page and AddToAny will know to use that instead of the current page’s url.
The big upside here is that this will work with any of the services used through AddToAny and you still get their Smart Menus. Not to mention that you’re now free to upgrade the plugin without worrying about it breaking.
The only downside I see is that if you use the “Standalone Services” this doesn’t seem to work. (Which is why I’m not using any yet.) For example, you still get the double-shortened URL and the “via @AddToAny” attribution with the Standalone Twitter service. According to Pat, it looks like they’re working on updating this.
Overall this is a much better approach than my previous hackfest. My thanks to Pat and AddToAny for taking the time to help me fix this!

