Skip to:

Limit long words

  • Hey Guys,

    We’re currently having some problems with longish words flowing out of the design, all normal words get text wrapped when they reach the end however long url’s or lines don’t, any ideas how to resolve?

    An example can be seen there, that url would even go into the background if i hadn’t shortened it, any ideas guys?

Viewing 12 replies - 1 through 12 (of 12 total)
  • Yeah, the easy fix for this is adding:

    .post {overflow: hidden; }

    Yes but that won’t wrap the word down or shorten it, it’ll just cut it off… any other solutions?

    You could try this:

    .post {overflow: scroll; }

    Should scroll the extra content… I think that’s what they are doing here, or something like that.

    It sounds like you’re looking for something like the proprietary word-wrap CSS property which works in IE browsers only, as far as I know.

    .post {word-wrap: break-word; }

    You want

    .post { overflow: auto; }

    which isn’t actually the automatic setting – but it’s the one that automatically adds a scrollbar if the post is too wide. Like multiline code here, it’ll add the scrollbar only if needed. Also handy for images.

    And lol at everyone suggesting something else. :P

    oh right, auto… duh! (slaps forehead)



    Are you interested in a plugin that will force spaces into long urls?

    Ahhh that auto worked a treat ;-) I’ve used the break-word as well for IE so it doesn’t even need to scroll when words are too long, in FF it just scrolls. Although a plugin to shorten long url’s words etc might be quite cool, like:


    If I get time next week I might make one… but don’t quote me on that :-P

    Thanks guys for the help!



    Don’t re-invent the wheel. WP-Chunk

    or Sam Ingle’s Link Truncator for WordPress can be hacked to support bbpress in under 5 minutes. There are probably others too.

    Here you are… ported from wp-chunk (literally only had to change the filter names)

    Plugin Name: bb-chunk
    Description: Shortens the display of urls so they won't break your site theme. Ported from wp-chunk 2.0 ( )
    Author: The How-To Geek
    Author URI:
    Version: 0.1

    function make_chunky($ret)

    // pad it with a space
    $ret = ' ' . $ret;
    $ret = preg_replace("#(^|[n ])([w]+?://[w#$%&~/.-;:=,?@[]+]*)#is", "$1<a href='$2' rel='nofollow'>$2</a>", $ret);
    $ret = preg_replace("#(^|[n ])((www|ftp).[w#$%&~/.-;:=,?@[]+]*)#is", "$1<a href='http://$2' rel='nofollow'>$2</a>", $ret);
    //chunk those long urls
    $ret = preg_replace("#(s)([a-z0-9-_.]+)@([^,< nr]+)#i", "$1<a href="mailto:$2@$3">$2@$3</a>", $ret);
    // Remove our padding..
    $ret = substr($ret, 1);

    function chunk_url(&$ret)

    $links = explode('<a', $ret);
    $countlinks = count($links);
    for ($i = 0; $i < $countlinks; $i++)
    $link = $links[$i];

    $link = (preg_match('#(.*)(href=")#is', $link)) ? '<a' . $link : $link;

    $begin = strpos($link, '>') + 1;
    $end = strpos($link, '<', $begin);
    $length = $end - $begin;
    $urlname = substr($link, $begin, $length);

    * We chunk urls that are longer than 50 characters. Just change
    * '50' to a value that suits your taste. We are not chunking the link
    * text unless if begins with 'http://', 'ftp://', or 'www.'
    $chunked = (strlen($urlname) > 50 && preg_match('#^(http://|ftp://|www.)#is', $urlname)) ? substr_replace($urlname, '.....', 30, -10) : $urlname;
    $ret = str_replace('>' . $urlname . '<', '>' . $chunked . '<', $ret);


    remove_filter('post_text', 'make_clickable');
    add_filter('post_text', 'make_chunky');

    Actually, seems to have flaky behavior unless you remove this line:

    remove_filter(‘post_text’, ‘make_clickable’);

    Seems to work pretty well otherwise.

    Whenever I try to activate this plugin I get this error message;

    Plugin could not be activated; it produced a Fatal Error.

Viewing 12 replies - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.
Skip to toolbar