sharing images – how do I add longdesc to img tag?
-
I’m hoping to share images to facebook using their attachment URL. I see this can be done by including a longdesc attribute on the img tag giving the attachment page URL.
I can prove this works by:
– adding the share-image class to the coblock masonry gallery
– inspect the image and edit the data-link attribute renaming it to longdesc
– clicking the facebook share now tries to share the attachment page and shows the correct imageMy issue is how to go about adding a longdesc attribute to the image tags.
I’ve tried adding filters like so:
function eis_add_longdesc($html, $id, $caption, $title, $align, $url) { $html = str_replace( " src=", " longdesc={$url} src=", $html ); return $html; } add_filter( 'image_send_to_editor', 'eis_add_longdesc', 999 );
and:
function eis_add_longdesc2($html, $id, $alt, $title) { $html = str_replace( " src=", " longdesc= src=", $html ); return $html} add_filter('get_image_tag', 'eis_add_longdesc2');
Both made no difference. I know the code in each case was incomplete, but I should’ve seen longdesc appear as an attribute of the img tag and did not.
I’m open to any solution including trying to edit the caption through code to add a facebook share I can create manually. I’ve attempted this also with no luck. I’m not a trained wordpress developer, but am quite good at coding and have been dabbling for a few months.
The page I need help with: [log in to see the link]
- The topic ‘sharing images – how do I add longdesc to img tag?’ is closed to new replies.