Skip to content

Instantly share code, notes, and snippets.

@tommcfarlin tommcfarlin/00-the-content.php Secret
Last active Oct 3, 2017

What would you like to do?
[WordPress] Adding Custom WordPress Image Attributes
private function addImageAttributes($content)
$content = mb_convert_encoding($content, 'HTML-ENTITIES', "UTF-8");
$document = new \DOMDocument();
$images = $document->getElementsByTagName('img');
foreach ($images as $image) {
$image->setAttribute('data-example', 'true');
return $document->saveHTML();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.