Support

Account

Home Forums Front-end Issues How do I automatically wrap images with div in WP WYSIWYG?

Solved

How do I automatically wrap images with div in WP WYSIWYG?

  • I’d like to use PHP to automatically wrap images in <div> instead of <p>, which I can do with the following code, but it doesn’t seem to work with the WP WYSIWYG add-on from ACF. Does anyone have a fix? Any help is appreciated!!

    // Replace  tags around images in the_content() with <div> tags
    function filter_ptags_on_images($content) {
      return preg_replace('/<p[^>]*>\\s*?(<a .*?><img.*?><\\/a>|<img.*?>)?\\s*<\/p>/', '<div>$1</div>', $content);
    }
    add_filter('the_content', 'filter_ptags_on_images');
    add_filter('acf_the_content', 'filter_ptags_on_images');
  • Hi @ericadecker

    Can you please update the WP WYSIWYG add-on from github. I just released a fix so that now it uses the acf_the_content filter correctly, and your code should then work.

    Thanks
    E

  • Elliot, you are awesome! Thank you so much. I adore this plugin.

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘How do I automatically wrap images with div in WP WYSIWYG?’ is closed to new replies.