Addthis custom share url with wp_get_attachment_link #ID
-
Hi All
Does anybody perhaps know howto include the id of an image dynamically within a custom addthis share url?
I’m sharing the gallery landing page with addthis, but require the image id as reference at the end of the url.
So the share url would look like the following:
https://www.yourdomain.com/my-photo-gallery/#image-1I’ve added a filter in functions.php to include the id within the gallery code:
add_filter( 'wp_get_attachment_link', 'add_image_attribute_id',10,6); function add_image_attribute_id($markup, $id, $size, $permalink, $icon, $text ) { $pos = strpos($markup, '<img '); if ($pos !== false) { return substr_replace($markup, '<img id="image-' . $id . '" ', $pos, strlen('<img ')); } return $markup; }
And i’ve added the following addthis .js code in my footer.php:
<script type="text/javascript"> $(".gal") .attr('rel', 'gallery') .fancybox({ beforeShow : function() { this.title = '<div class="addthis addthis_default_style "><a href="' + this.href + '">" addthis:title="' + this.title + '" class="addthis_button_preferred_1"></a><a href="' + this.href + '"></a><a href="' + this.href + '"></a><a href="' + this.href + '"></a><a href="' + this.href + '"></a><a href="' + this.href + '"></a></div>'; }, afterShow : function() { addthis.toolbox( $(".addthis").get() ); addthis.counter( $(".addthis_counter").get() ); }, helpers : { title : { type : 'inside' } } }); </script>
Much appreciated.
Regards.
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Addthis custom share url with wp_get_attachment_link #ID’ is closed to new replies.