1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

HOWTO remove <p> tags from images in WordPress

Discussion in 'Blogging' started by Junkfood00, Jun 27, 2013.

  1. Junkfood00

    Junkfood00 Elite Member

    Joined:
    Sep 13, 2011
    Messages:
    1,949
    Likes Received:
    1,336
    So I stumbled upon this problem of images having their own p tags and messing up the layout, they were inserted by the core system of WP.
    And after a lot of searching and trial of codes written by inexperienced coders, I found the solution.

    WordPress has this thing called wpautop that inserts p tags whenever you press enter in the visual editor and whatever. This thing tries to avoid conflicting types such as shortcodes but sometimes it cannot detect things well and pukes out another p tag.

    All you have to do, which seems to work for me is create a folder in the plugins folder and a php file inside that folder with the same name and insert this:

    Code:
    <?php
    remove_filter( 'the_content', 'wpautop' );
    add_filter( 'the_content', 'wpautop' , 99);
    
    
    then you activate the plugin from your panel.

    Hope it helped.
     
    • Thanks Thanks x 2
    Last edited: Jun 27, 2013
  2. Conor

    Conor Jr. VIP Jr. VIP

    Joined:
    Nov 7, 2012
    Messages:
    3,356
    Likes Received:
    5,418
    Gender:
    Male
    Location:
    South Africa
    Home Page:
  3. Jesusp19

    Jesusp19 Regular Member

    Joined:
    Mar 24, 2013
    Messages:
    471
    Likes Received:
    171
    nice to know :)
     
  4. VIC SEO

    VIC SEO Elite Member

    Joined:
    Feb 19, 2010
    Messages:
    2,156
    Likes Received:
    363
    Gender:
    Male
    Occupation:
    SEO Specialist
    Location:
    iSynergyMedia
    Home Page:
    Hi there - the original post (Word Press P Tag removal on Fublo blog) has been updated with code for stripping p tags on iframes too.
    Plus there are links to other WP articles with related discussions and regular expressions for HTML5 tweaks.
     
  5. Junkfood00

    Junkfood00 Elite Member

    Joined:
    Sep 13, 2011
    Messages:
    1,949
    Likes Received:
    1,336
    Trust me, I've tried almost every single regular expression code out there and non of them worked for me.

    Well, there might exist another solution but this is a working one for sure.