WordPress.org

Ready to get started?Download WordPress

Forums

<div> tags replaced by <p> How do I make it stick? (10 posts)

  1. AnnBaxter
    Member
    Posted 6 years ago #

    My <div> tags in the code window keep getting replaced with <p> tags after the page is saved. How do I stop this from happening?

    Ann

  2. Jess Planck
    Member
    Posted 6 years ago #

    Since the DIV tag is considered more as layout markup the developers convert it to a paragraph to be more writer / semantic friendly. For most people this may be a good idea, but if you understand what you are doing DIVs can be useful.

    It's one of the reasons I wrote WP Super Edit. It's a plugin specifically to manipulate the Visual Editor. You can find it at http://www.funroe.net/projects/superedit/.

    I don't know if this is truely your problem since you mentioned that you were saving from code view. If the plugin doesn't work for you, you might want to provide your WordPress version.

  3. AnnBaxter
    Member
    Posted 6 years ago #

    Thank you very much, ev3rywh3re. I'll look into this plugin.

  4. godofcomics
    Member
    Posted 6 years ago #

    I am having the same problem. I want to post divs codes among with text, but the editor keeps converting them to P's.

    Is there an easy way to just make my WordPress simply stop doing that with divs?

    my version is 2.3.1 (latest).

  5. godofcomics
    Member
    Posted 6 years ago #

    bump. please help ^^

  6. godofcomics
    Member
    Posted 6 years ago #

    just to confirm: I want to cancel this option, I don't want wordpress converting my "divs" to "ps", something easy for a newbie programmer.

  7. aarondiers
    Member
    Posted 6 years ago #

    Found an answer for this, and thought I'd share it here.

    Edit this file:

    wp-includes/js/tinymce/tiny_mce_config.php

    Line 26 reads as follows:

    $valid_elements =
    ‘p/-div[*],-strong/-b[*],-em/-i[*],-font[*],-ul[*],-ol[*],-li[*],*[*]’;

    Remove the first portion, like so:
    $valid_elements =
    ‘-strong/-b[*],-em/-i[*],-font[*],-ul[*],-ol[*],-li[*],*[*]’;

    After you've done that, be sure to reset your browser cache.

  8. jexanalytics
    Member
    Posted 6 years ago #

    aarondiers, you are awesome.
    Thanks for that. Did it, it worked, You Rock.

  9. Aaron D. Campbell
    Member
    Posted 6 years ago #

    Actually, all you have to do is make up a bogus CSS class (call it "this_does_nothing" or something like that) and add it to any divs that you want to keep. Since WP thinks that the markup has styling applied, it will leave it alone.

  10. perywinkle
    Member
    Posted 6 years ago #

    Oh, Nice! Did WP stop tampering with div tags?
    I do believe so!
    Now I can stop pulling what's left of my hair out.
    I've been using super edit for just that reason.

Topic Closed

This topic has been closed to new replies.

About this Topic