Support » Themes and Templates » Empty content creates an extra <BR/>

  • 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

Viewing 3 replies - 1 through 3 (of 3 total)
  • 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.

    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...');

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

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Empty content creates an extra <BR/>’ is closed to new replies.