Home / functions.php / Automatically wrap images in the_content with custom html
  • How to Automatically wrap images in the_content with custom html

    automatically-wrap-images-in-the_content-with-custom-html

    Adding this snippet to the functions.php of your wordpress theme will automatically wrap images in the_content with any custom HTML that you wish.

    wordpress snippet : PHP

    <>
    function filter_images($content){
        return preg_replace('/<img (.*) \/>\s*/iU', '<span class="className"><b><img \1 /></b></span>', $content);
    }
    add_filter('the_content', 'filter_images');
    

    ( WordPress codex functions, hooks, in this snippet. )

    the_content, add_filter,
  • Luke

    I love you man! great script

  • http://soffile.blogspot.com/ Danish Raza

    great!