Trying to automatically wrap all image tags within a field that’s currently managed with CKEditor. Would really like to handle it all with PHP.
So this would be an example of a field’s random contents:
<p>
Intro text here<br />
<img alt="sample desc" src="/images/example1.jpg" />
Long article text here...
<img alt="sample desc" src="/images/example2.jpg" />
Short article text here...
<img alt="sample desc" src="/images/example3.jpg" />
</p>
And I would need to change the above code to this, wrapping each image tag with a link using a unique id, href matching the img’s source and title matching alt text:
<p>
Intro text here<br />
<a id="image1" href="/images/example1.jpg" title="sample desc">
<img alt="sample desc" src="/images/example1.jpg" />
</a>
Long article text here...
<a id="image2" href="/images/example2.jpg" title="sample desc">
<img alt="sample desc" src="/images/example2.jpg" />
</a>
Short article text here...
<a id="image3" href="/images/example3.jpg" title="sample desc">
<img alt="sample desc" src="/images/example3.jpg" />
</a>
</p>
Thanks for any help you can provide!
If it’s arbitrary HTML that comes from external sources then it’s most simple with e.g. querypath
You might want to inject
id=andtitle=likewise in the loop, but that’s about it.