My client has decided he wants to add inside the article body, for each image, the caption below the img tag.
I know WordPress has this shortcode built in, but since there are more than 300 articles, it would take a lot of time.
[caption id="attachment_47" align="alignnone" width="300"] test test[/caption]
To recap, for each tag inside my article body, I want to return that tag and after that a paragraph tag which contains the caption of the image.
I found the wp_get_attachment_image() method but I can't make the connections when trying to get the article body and filtering those images in order to add the paragraph tag after each image.
Thanks a lot in advance!
img
tags with a shortcode if the structure allows us, we can do a search and replace database operation for all of them. The other solution I have for you is a function that searches through the content of each post, finds each img tag, gets its id, retrieves the caption associated with that image, and then appends a p tag with the caption below the img tag. But it involves manipulating HTML viaDOMDocument
, and it can be weird sometimes.