WordPress.org

Ready to get started?Download WordPress

Forums

Unwanted <p> tags added to pages (12 posts)

  1. stroppy
    Member
    Posted 6 years ago #

    Hello,

    I am becoming infuriated by the WordPress editor adding unwanted paragraph tags whilst editing pages. I have a few pages where I use divs to organise content, and WordPress adding these paragraph tags in between divs prevents my pages from becoming XHTML valid.

    I am aware of the wpautop function and that there is plugins to disable this, however I do not want to have to do this as it is handy when writing regular blog entries/pages which do not require divs.

    In versions prior to 2.5, removing p/-div[*], from the line $valid_elements =
    ‘p/-div[*],-strong/-b[*],-em/-i[*],-font[*],-ul[*],-ol[*],-li[*],*[*]’;
    in wp-includes/js/tinymce/tiny_mce_config.php fixed this problem. However, in 2.5 and above I can no longer find this line in the aforementioned file.

    Is there a similar solution for versions 2.5 and above, or any hack/plugin that will fix my problem?

    Any help in this matter would be greatly appreciated, thank you.

  2. Ivovic
    Member
    Posted 6 years ago #

    your problem isn't so much the wpautop function, it's that you're using the visual editor.

    Let me see if I can make this point as strongly as possible, in case there's any further argument...

    If you're adding markup to your posts, you should NOT be using the visual editor. Either find a way to add your markup via a custom filter, so you can avoid inserting into your posts, or STOP USING THE VISUAL EDITOR.

    The visual editor is for people who don't know what markup is.

    I can't stress that enough.

    Without using the visual editor, you can add div tags to your posts, if you leave a blank line between your previous/following paragraphs and the div. This blank line will not be evident in your final output.

  3. artsy.ca
    Member
    Posted 6 years ago #

    Though I agree with you regarding the visual editor, it seems to be happening with the old-school editor as well. Just a bunch of unwanted <p> tags wrapping everything. It's very tedious.

  4. PJ Brunet
    Member
    Posted 6 years ago #

    "I can't stress that enough."

    I'm not using the visual editor. Here you go straight from Firebug:

    <p>
    <img style="width: 100px; height: 200px;" src="http://sitdownsellup.com/pj/red-x.png"/>
    </p>

    Those paragraph tags are not mine. I just deleted the entire tinymce directory off my server to be sure, problem is still there, and no it's not cached.

    Time for phpmyadmin, ugh.

  5. PJ Brunet
    Member
    Posted 6 years ago #

    OK, phpmyadmin was of no help, the paragraph tags are added after the fact.

    What is the function I need to start hacking? Or maybe I can neuter the paragraph tag with CSS, if that's even possible.

  6. PJ Brunet
    Member
    Posted 6 years ago #

    Came up with a temporary hack, added this to my style.css:

    div#post-132.post div.post-entry div p {margin:0 0 -3px 0;}

    If anyone finds a better solution, let me know: pj@pjbrunet.com

    I don't know why WP would add paragraph tags to posts after they've been saved to mysql, but maybe there's a good reason.

    Straight from phpmyadmin:
    <div style="width:200px;border:1px gray dotted;"><div style="float:left;text-align:left;width:80px;padding:10px;">Write about your picture here.</div><img src="http://sitdownsellup.com/pj/red-x.png" style="width:100px;height:200px;" /></div>

    And straight from "view source" firefox:
    <div style="width:200px;border:1px gray dotted;">
    <div style="float:left;text-align:left;width:80px;padding:10px;">Write about your picture here.</div>
    <p><img src="http://sitdownsellup.com/pj/red-x.png" style="width:100px;height:200px;" /></div>

    See the "<p>" that got added? Very strange.

    "Without using the visual editor, you can add div tags to your posts, if you leave a blank line between your previous/following paragraphs and the div. This blank line will not be evident in your final output."

    No, that didn't work either.

    Hey, no wonder I'm single ;-)

  7. RandomlyWriting
    Member
    Posted 5 years ago #

    I'd really like to get an answer/fix about this problem. Same situation - not using the visual editor .. same result, unwanted paragraph tags everywhere. Anything WordPress?

  8. Luap777
    Member
    Posted 5 years ago #

    Same problem. The <p>'s are very very much unwanted. I want the code that I put in the (non-visual) editor to be untouched.

  9. Luap777
    Member
    Posted 5 years ago #

    Ignore my reply. Hope it won't break anything, but I commented out

    // add_filter('the_content', 'wpautop');

    in default-filters.php

  10. Gr1f
    Member
    Posted 5 years ago #

    Luap777

    THANKS!
    that stupid <p> tag at the beginning of every post was driving me nuts!!!

  11. nintensity
    Member
    Posted 5 years ago #

    amazing. good job man!

    Keep in mind it also takes out the <p> tag in front of my blockquote as well as my cite tags. but good work nonetheless.

  12. robsku
    Member
    Posted 5 years ago #

    There is a plugin that allows per post setting to disable this annoying feature. It's called WP-Unformatted, the short description says:

    With this enabled, you can add a custom field of ’sponge’ set to ‘1′ to a post to disable the auto formatting and a custom field of ’sandpaper’ set to ‘1′ to a post to disable the auto smart-quote conversion.

    You can get it at: http://alexking.org/projects/wordpress

    It only took some googling to figure out what caused the problem (thanks to this thread for an answer) and only bit more to find this plugin for it :)

Topic Closed

This topic has been closed to new replies.

About this Topic