Support » Plugin: CMP - Coming Soon & Maintenance Plugin by NiteoThemes » Need to remove automatic p tags around images

  • Resolved Alicia St Rose

    (@laughhearty)


    Hi!

    I’m adding an image to the content, however it keeps getting wrapped in p tags so I can’t float it.

    I’m using this code in an attempt to get rid of them:

    function filter_ptags_on_images($content) {
        $content = preg_replace('/<p>\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/p>/iU', '\1\2\3', $content);
        return preg_replace('/<p>\s*(<iframe .*>*.<\/iframe>)\s*<\/p>/iU', '\1', $content);
    }
    add_filter('acf_the_content', 'filter_ptags_on_images');
    add_filter('the_content', 'filter_ptags_on_images');

    I don’t think the_content works in this case because you are using a custom field? Is there a way around this?

    Thanks!

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author NiteoThemes

    (@niteo)

    Hello, filters do not work in CMP as it is outside of WordPress loop in order to make it work.

    Why don’t you float whole paragraph with the image? – you can do something like this:

    <p class="float-left"><img src="#" alt=""></p> and float class .float-left ?

    • This reply was modified 7 months, 3 weeks ago by  NiteoThemes.
    Plugin Author NiteoThemes

    (@niteo)

    Closing…

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.