WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How to remove the <p>'s from the_content? (10 posts)

  1. revje
    Member
    Posted 6 years ago #

    Hey there :)

    I'm just starting to figure out WordPress and I already bumped into an oldschool CMS-thing! Paragraphs where I don't want them! ;)

    In 'the_content' there appears to be a <p> tag (and a </p> one of course) and I'd like to know the file where it puts the tags in the var. I've been searching among some files like edit-form.php to post.js

    Goal: If the content would be "Hello world", having <?php the_content(); ?> print "Hello world" rather than "<p>Hello world</p>".

    Might be I'm thinking too complex for it atm, might be it ain't that easy - anyone who wants to help me out? :)

  2. TaxPolicy
    Member
    Posted 6 years ago #

    I want to accomplish exactly the same thing. Have read through the_content() and the functions it calls, and anything they call, ... and I can't find the place where the <p>, </p> get injected. Looking forward to seeing a solution posted...

    - Mike
    [ admin for the tax policy blog on optimalportfolio.net ]

  3. RoseCitySister
    Member
    Posted 6 years ago #

    You can turn off the visual editor in your profile, but what I would do is enclose the content in div tags. WordPress used to replace <div> with <p> but 2.5 fixed that.

  4. revje
    Member
    Posted 6 years ago #

    Thanks for the tip RoseCitySister :) Imma try that, 'tho I will keep searching a bit for the part where it's added to the_content. I'm a huge fan of minimalism ^^

    ps: If anyone knows where the <p>-tag is added, please do still reply. Thanks! :)

  5. TaxPolicy
    Member
    Posted 6 years ago #

    RoseCitySister,

    I looked at the post content in HTML mode - it doesn't have leading <p>'s or trailing </p>'s. They're being injected by either WordPress or the Theme.

    -Mike
    [sig moderated. please don't]

  6. revje
    Member
    Posted 6 years ago #

    Problem sort of fixed through adding the <div>-tags around <?php the_content() ?>. I guess I'll have to stop being so strict on my sourcecode. I always like to have the smallest bit of HTML in my page, and have it totally designed by CSS. (For obvious reasons and also as a training for myself)

    So, confirmed that the div-fix works (: Thanks again.

    @TaxPolicy, try to add <div></div> around <?php the_content() ?> in your theme's HTML. It's not totally the answer I was looking for tbh, but for the design/looks of it it works like a charm.

    Cheers :)

  7. TaxPolicy
    Member
    Posted 6 years ago #

    Revje,

    I think I know why WordPress wants (needs) <p> around the content... When you have multiple paragraphs in the post content, you need them delimited from each other. I posted code from index.php and style.css below... Probably need to get control of the spacing before and/or after the content in some other way - the question is how?

    -Mike
    -------------------------------------
    <div class="post-author">
    <?php _e('By '); the_author(); ?>
    </div>

    <div class="post-content">
    <?php the_content(__('Read the rest of this entry »')); ?>
    </div>

    <div class="post-metadata">
    <?php _e('Posted in '); the_category(', '); ?> |
    <?php edit_post_link(__('Edit'),'',' |'); ?>
    <?php comments_popup_link(__('No Comments'), __('1 Comment'), __('% Comments')); ?>
    </div>
    .......................................................................
    the CSS looks like:
    .post-author {
    font-size:8pt;
    color:#003366;
    background-color: #FFFFFF;
    /* margin-bottom:3em; orig - removal has no effect */
    margin-bottom:1em;
    }
    .post-content, .comment-content {
    font-size:10pt;
    color:#333333;
    }
    .post-metadata {
    text-align:center; /* my addition - no effect */
    font-size:8pt;
    color:#003366;
    background-color: #FFFFFF;
    /* padding-left:3em; orig - removal has no effect*/
    }
    .......................................................................
    The resulting code looks like:

    <div class="post-author">By {username}</div>
    <div class="post-content">
    <p>post content paragraph1...</p>
    <p>post content paragraph2...</p>
    </div>
    <div class="post-metadata">
    Posted in ...
    </div>

  8. Norke
    Member
    Posted 5 years ago #

    I know it's resolved already, but this would have been a better solution:

    In stead of using <?php the_content(); ?> you could have used <?php echo get_the_content(); ?> That returns without the p tag.

  9. mynetweblogs
    Member
    Posted 5 years ago #

    Does using <?php echo get_the_content(); ?> have any negative effect like extra load time or hitting the server more?

  10. kevinlanteri
    Member
    Posted 5 years ago #

    For other peoples that might be looking for a similar solution without having to touch the_content() (for plugin issue or so...),
    open functions.php on your theme, or create one, and put this single line of code:

    remove_filter ('the_content', 'wpautop');

    it'll remove the whole wordpress auto-formatting, but that it's all or nothing, so use carefully

    another (cool and clean) solutions might be to used alex king's WP Unformatted

    hope it'll help...
    KL

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.