• 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 5 years, 8 months ago by NiteoThemes.
    Plugin Author NiteoThemes

    (@niteo)

    Closing…

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Need to remove automatic p tags around images’ is closed to new replies.