2

folks.

I need to put a piece of code after every post image (post attached image). it's something like this:

<img class="alignnone size-full wp-image-3079" src="imgurl.jpg" alt="02" width="2592" height="1936">
<div>some piece of code here</div>

It will be a share button to share the image instead the post, so every image will need a custom code to share the image url.

There's a way to do this?

2
  • So this is not an image caption? What did you try so far? What if the image is wrapped in some HTML tags? Is it a static snippet? What about using e.g. jQuery?. Is this restricted to the post content? Please update the question with more info, thanks.
    – birgire
    Commented May 30, 2016 at 14:52
  • This gonna be a dinamic code, jQuery didn't worked like I wanted, I will make a share button to share the image instead the post. Commented May 30, 2016 at 14:56

1 Answer 1

3

Try get_image_tag filter:

add_filter('get_image_tag', function($html, $id, $alt, $title, $align, $size)
{
    return $html . '<div>some piece of code here</div>';
}, 10, 6);

References:

1
  • I use get_image_tag filter and it's work. Thanks @dan! Commented May 30, 2016 at 19:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.