• Hi, I’m trying to write a plugin and I’m a bit stuck. The plugin get’s images from posts with a certain class.
    Here is my code:

    <?php
    /*
    Plugin Name: Get The Image
    */
    
    add_filter('the_content', 'ed_get_image');
    
    function ed_get_image($content)
    {
           if(preg_match('!<img(.*?)class="imagetest"(.*?)/>! iU', $content, $matches))
           {
                   return $matches[0];
           } else {
                   return false;
           }
    }
    
    ?>

    The problem I have though is that my plugin is always on. How do I make it so that people have to insert the function into the template first before it is used?
    E.g. They’d have to put something like: ‘<?php ed_get_image(); ?>’ in their template before the plugin is used.

The topic ‘Help with my image plugin’ is closed to new replies.