Support » Plugins » Limiting Link Length in comments

  • I wanted to ask if anybody knew a good way to limit the maximum length allowed in links provided in comments.

    I have a fixed width design, and everynow and then, if someone leaves a link too lengthy in the comments, it busts up the design.

    I did find one solution that works. It’s pretty slick and written in javascript.

    I’d really like a good WordPress plugin though, as I like using JS as little as possible…

    Ideally, any WordPress plugin would change the links of the fly, leaving the originals untouched in the database. (That way, I could go back to the original if I ever wanted to by turning off the plugin).

    I did search around before posting, but couldn’t find what anything…


Viewing 14 replies - 1 through 14 (of 14 total)
  • Something like this?

    Break Comment Text
    download plugin | view source

    Download the plugin file, upload to your wp-content/plugins directory, and activate Break Comment Text under Plugins. The plugin has two user-configurable variables you should know about:

    $cols = Maximum # of characters allowed for any text string (60 by default). Those longer than $cols are “broke” into two (or more) lines.

    $break = The break or cut character (‘ ‘ (space) is the default). A space or break tag () are recommended.

    You can change these variables either through the Plugin Editor in WordPress, or in a text editor offline.

    Note: The plugin is based on one of my first WordPress user-requested bits of code, and though cleaner than that original work, I’ve never been completely happy with the actual text breaking portion. I’ll look that over at some point and make it a little smarter (as well as faster).

    Thanks for the plugin Kafkaesqui,

    My comment page broke after some links were inserted. I’ve tried everything to re-adjust the page, but no go. I still get horizontal scrolling in IE (FF fixed itself with your plugin) – very, very minimal, but its there just the same. Before the comments were posted, no breakage was evident.

    I’ve activated your plugin, and I’ve reset the variables to $cols50 & 40 – still no improvement.

    Any suggestions? Should I go even smaller?

    PS: I sincerely hope I haven’t hijacked this thread – I assume that if we have a common problem we can add to it? 🙂

    Mark (podz)


    Support Maven

    overflow:hidden for the textarea ?

    Thanks Podz. I’ll try your suggestion.

    Nope. Didn’t work. Any idea why I have this flaw now? Even with the plugin?

    What I’ve done to try and fix this sudden problem.

    I removed all links from the affected comment page: Didn’t fix it.

    I removed all blockquote elements, just in case. No goer.

    I checked all links in the article; added ‘rel:nofollow’. Didn’t fix it. (I only got this prob after a couple of links were inserted into comments, anyway.)

    Altered my CSS to narrow the comment Form, textarea, and entry widths. Didn’t fix it.

    Used IE Hack – didn’t fix it.

    Hard Refresh – didn’t fix it.

    Copied all existing CSS backup files I had stored away, and pasted them into the theme, hoping to revert back to previously cleared condition. Didn’t fix it.

    Now I’m truly stumped. Any suggestions would be greatly appreciated. Link here


    Sorry IE6 only, please. 🙂

    It’s definitely an IE bug somewhere – FF is validating beautifully. I just can’t seem to find it.

    I’ve decided that this is a no-worry situation. The scroll is so bloody minor and it only occurs on this page.

    So resolution not required, unless someone wants to provide it


    Here’s one thing that might cause your problem. IE has a bug where it calculates widths, and then applies italics formatting to the text. If italics run up against the right margin of a block, this will push that block slightly wider… You can test this simply by saving the html of the post that’s causing you problems as a local file on your computer. Then, edit the source of that local file to remove all italics. If that fixes your problem, you’ve identified what’s causing it. You can adjust your site’s layout to allow for some extra room if this happens. (If you’re taking up 100% of the width, take up 99% or 98%, whatever). Anyway, this might help you.


    First off, the urls you provided give a 404 error.

    Secondly, would a plugin like you’re talking about work? Remember, a link has two parts. [a href=”x”]y[/a]

    We’d need to chop off the length of ‘y’ if it was too long, while leaving ‘x’ unchanged so that the link would still work.

    @jayp – thanks for the info. I removed all italics on the comments, but still hasn’t rectified the situation.

    Not to worry – it isn’t that bad, and only occurs on one page.

    Just to clarify, could italics anywhere in the page be causing the problem? I wasn’t thinking it was just the comments that would cause the trouble.

    If you’re only having the problem on one post, then that obviously says it ain’t the italics.

    If you want to fix it bad enough, just change one thing at a time until you can isolate what’s causing the problem. Then the next step is figuring out a solution…

    Now back to my original question – Anybody know a WordPress equivalent to the JS script I linked to in my original post on this thread?

    First off, the urls you provided give a 404 error.

    Issues with the site (thank you WordPress 2.0!). Should work now.

    Secondly, would a plugin like you’re talking about work? Remember, a link has two parts. [a href=”x”]y[/a]

    It works by passing over the tags. Anything between < and > should be ignored by the plugin (this is the part that could be made smarter, since one could fool it by placing long strings of text between the tag characters). I’ve developed several score scripts and programs over the years which needed to account for HTML, so no need to remind me. ;)


    I tried your plugin, but no luck.

    It turned the following link:

    into this:


    which is even longer and only made the problem worse. The actual link (the href attribute) still pointed to the right place.

    I may play around with it myself and see if I can code a solution… (Or I may not.)

    If you know what the problem is or have a solution, I’m interested.

    I just realized… You’re not trying to shorten the length… Only add a space so it wraps.

    I was wanting something that took a long length and shortened it, putting in […] into the shortened part.

    I’ll play with it.

    This plugin does auto-linking of urls, with the option to truncate the link text (which seems to be what you’re looking for):

    Plugin: Auto-hyperlink URLs

    Thanks Kafkaesqui. I tried that plugin and it worked beautifully 🙂

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Limiting Link Length in comments’ is closed to new replies.