WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Force one space between periods (7 posts)

  1. fodden
    Member
    Posted 3 years ago #

    Despite repeated assertions that browsers will collapse two consecutive spaces, I find that on my multi-author blog, two spaces after a period are displayed just fine. I don't want this. What I want is to be able to force one space only between sentences. Does anyone know of a way to do this?

    The blog in question is http://www.slaw.ca

    Thanks.

  2. fodden
    Member
    Posted 3 years ago #

    Yes, well, I meant "Force one space between sentences" of course. Sorry about that.

  3. ClaytonJames
    Member
    Posted 3 years ago #

    I 'm making the assumption that you may want to get rid of the space between paragraphs?

    Find this in the style sheet:

    div.entry p {
    margin: 10px 0;
    font-family: Verdana, Arial, sans-serif;
    font-size: 11px;
    line-height: 160%;
    color:#000;
    }

    Try changing it to this:

    div.entry p {
    margin: 0;
    font-family: Verdana, Arial, sans-serif;
    font-size: 11px;
    line-height: 160%;
    color:#000;
    }

    And see if the margin change makes the difference you are looking for. Make a backup before editing, just in case.

  4. fodden
    Member
    Posted 3 years ago #

    Thanks, ClaytonJames. But it's the two spaces after the end of a sentence that I want to get rid of. This is a multi-author blog, and some authors use one space between sentences, but others are stuck with the old typewriter rule and use two. It's the latter I'd like to correct automatically. So… how might I ensure only one space between sentences, i.e. after a period.

  5. keesiemeijer
    moderator
    Posted 3 years ago #

    Put this in your theme's functions.php :

    function remove_spaces($the_content) {
        return preg_replace( '/[\p{Z}\s]{2,}/u', ' ', $the_content );
    }
    
    add_filter('the_content', 'remove_spaces');
  6. fodden
    Member
    Posted 3 years ago #

    A thousand thanks, Keesiemeijer. (Dank u zeer?). I must must must learn regular expressions.

  7. Zoinks! Graphics
    Member
    Posted 3 years ago #

    Wow, I've been searching for a solution like this FOREVER! The tricky part is I want to search for "double-space" but that inevitably pulls up discussions about LINE spacing, not spaces between sentences/after periods.

    Oddly, while most themes display two spaces in a row the way they should (as a single space) some display two spaces AS two spaces. The crazy thing of it all is that the source code doesn't show "  " as one would expect, but rather 2 spaces " ". So that leads me to think that some themes have a funky CSS that displays " " as double-space.

    All ranting aside, that's why this function is so crucial, and probably should be built into the WP core. Perhaps with an option to be disabled in the admin in case the blogger wants to use double space. Just a thought...

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags