Dynamically adding Captions to images

Question

I have a site where the author has included Amazon Affiliate links. They’ve done this by adding the URL to product images.

I’m wondering if there’s a way to add a function that will automatically add a wp-caption below these images if they’re linked to Amazon.

Basically the condition would need to be: if an href containing an image is linked to a domain including ‘amazon’, add a caption below that image that says “Buy Now”. The caption would also have the same link as that image.

I’ve been able to do this with some hacky jQuery, but it doesn’t always fire properly. I think there might be a better way…

Thanks

--------------------------------------------------

>>> Share a link to this question, just copy and paste the code bellow on your web page <<<

<a href="https://www.wptricks.com/question/dynamically-adding-captions-to-images/">

Dynamically adding Captions to images</a>
0
, , David 2 weeks 0 Answers 21 views 0

Leave an answer