WordPress.org

Ready to get started?Download WordPress

Forums

Empty content creates an extra <BR/> (4 posts)

  1. Mads Phikamphon
    Member
    Posted 6 years ago #

    Aloha,

    My post content is sometimes empty (some of my content is stored in a separate database).

    Problem is that the_content() creates a BR/ when it sees that the content is empty :(

    Can I get rid of that BR/ somehow - or call the_content in a way, so I get access to the content without having to display it?

    The BR/ messes up my layout, so I would love to get rid of it.

    Thanks, Mads

  2. anmari
    Member
    Posted 6 years ago #

    You can try

    .entry-content ul{ margin-top: 0;}

    in your stylesheet.

    The empty content is usually when you have a sitemap or archives template which is usually listing items. So the content div after the post/page title is followed by a ul. So remove all the extra space you can when that situation arises and it mitigates the effect of the <br />.

    You could even be more specific and try to isolate only those pages using the page id.
    body.pageid-xx .entry-content ul{ margin-top: 0;}

    Note I am using SandboxPlus theme so have taken my css selectors from there. You would have to look at what your theme does.

  3. thewebdude
    Member
    Posted 5 years ago #

    I have narrowed down where this is happening. It is a part of the filtering process by the function "wpautop" in the file: {wp-location}\wp-includes\formatting.php
    This is the comment describing the function:

    /**
     * Replaces double line-breaks with paragraph elements.
     *
     * A group of regex replaces used to identify text formatted with newlines and
     * replace double line-breaks with HTML paragraph tags. The remaining
     * line-breaks after conversion become <<br />> tags, unless $br is set to '0'
     * or 'false'.
     *
     * @since 0.71
     *
     * @param string $pee The text which has to be formatted.
     * @param int|bool $br Optional. If set, this will convert all remaining line-breaks after paragraphing. Default true.
     * @return string Text which has been converted into correct paragraph tags.
     */

    You can disable the $br argument, but then all
    tags will be removed. I don't believe wordpress generates br and p tags by whitespace. A workaround is to check to see if the content is empty, then do some conditional processing:

    if(get_the_content() != ""){
    	the_content('Read the rest...');
    }
  4. bitkahuna
    Member
    Posted 5 years ago #

    thewebdude - THANK YOU! the conditional worked perfectly in a template i am working on. much appreciated.

Topic Closed

This topic has been closed to new replies.

About this Topic