I'm trying to build a plugin that adds a class to all images in my articles. So far I have the following code:
<?php
// no direct access
defined('_JEXEC') or die;
jimport('joomla.plugin.plugin');
class plgContentAddImageClass extends JPlugin
{
public function __construct(&$subject, $params)
{
parent::__construct($subject, $params);
}
public function onContentPrepare($context, &$article, &$params, $offset = 0)
{
// Article Content
$content = &$article->text;
// Find images and add a class
}
?>
But I'm stuck as to how I can find images in the content and add a class to them. Also, the images might have a class already, in that case I want to add a new one to the existing classes.
Edit:
I have a plugin that watermarks any image with a certain class, but because the site already has lots of images, I would like to add the class to the images dynamically instead of going through each <img>
tag on the site and add the classes.
I'm aware that I can target all images with CSS, it just doesn't help in this case.