WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Shorten long hyperlinks in comments (4 posts)

  1. ChillPenguin
    Member
    Posted 7 years ago #

    I'm trying to find a way to automatically shorten long hyperlinks that are posted in the comments. For example, turn something like:

    http://www.somedomain.com/blog/archive/2006/08/23/index.php

    into something like:

    http://www.somedomain.com/b...

    Currently, I have a design that is far too thin, which causes even moderately long hyperlinks to break the design. Making any changes to the design is not an option, so I am looking for a code solution.

    Any ideas? Thanks in advance.

  2. Samuel Wood (Otto)
    Tech Ninja
    Posted 7 years ago #

    The trick is in the make_clickable function. This filter is what converts the non-links into links. So to make it act differently, you just have to modify it to replace the links with shorter bits.

    However, modifying core code is no good either, so the better way is to clone the function, and modify the clone. Then you can plug it in where you want it. In your case, in comment text.

    Here's a quick hack I did of the function. It's untested, but I think it'll work.
    http://ottodestruct.com/blog/wp-content/uploads/2006/08/short_links.txt

    You'd put that code into your theme (like functions.php) or into your my-hacks file, or into a plugin.

  3. moshu
    Member
    Posted 7 years ago #

    CP, see also this thread:
    http://wordpress.org/support/topic/58622?replies=15
    (found by search, BTW...)

  4. ChillPenguin
    Member
    Posted 7 years ago #

    Searching is my friend :)

    Thanks for the replies guys. I just came back to say that this plugin was able to meet my needs (listed in the codex):

    http://www.village-idiot.org/archives/2006/06/29/wp-chunk/

    The solution couldn't be simpler. Thanks again!

Topic Closed

This topic has been closed to new replies.

About this Topic