[resolved] How Can I Create Auto-Links (11 posts)

  1. olci
    Posted 8 years ago #

    i know other automatic creating links but i am searching another thing.
    i want to make this :

    when i write on my panel :

    it's changing like this :
    http://www.adomain.com/sdf...df.html (but same url at top)

    vbulletin and smf have this hack.

    how can i make like this hack ?
    i have a tall links :(

    i hope, i can explain my problem.

  2. fitztrev
    Posted 8 years ago #

    I released a plugin that does this: Comment Url Compacter

    It does it for comments only, but add this line to it, and it will work the way you want, too:

    add_filter('the_content', 'compact_comment_urls');
  3. olci
    Posted 8 years ago #

    i added this line but it's not work on my content pages.
    it's just working on comments yet.

    any mistake ?

    Plugin Name: Comment URL Compacter
    Plugin URI: #
    Description: When long URLs are left in a comment, they can break a theme and be obnoxious.  This plugin shortens them so they look much nicer.
    Version: 0.1
    Author: Trevor Fitzgerald
    Author URI: http://www.trevorfitzgerald.com/
    function compact_urls($link) {
    	if ( strlen($link) > 50 ) {
    		$link = preg_replace('/(https*:\/\/)*(www.)*/', '', $link);
    		$link = substr($link, 0, 18) . '&hellip;' . substr($link, -20);
    	return $link;
    function compact_comment_urls($comment) {
    	$pattern = '/<a(.*)>(.*)<\/a>/ei';
    	$replace = '"<a$1>" . compact_urls("$2") . "</a>"';
    	$comment = preg_replace($pattern, $replace, $comment);
    	return $comment;
    add_filter('comment_text', 'compact_comment_urls');
    add_filter('the_content', 'compact_comment_urls');
  4. olci
    Posted 8 years ago #

    is nobody help me :(
    please brada..
    it's very important.

  5. fitztrev
    Posted 8 years ago #

    I just tested exactly like you have pasted above and it worked perfectly.

  6. olci
    Posted 8 years ago #

    i am using,
    2.3.3. version ?
    what about yours ?
    it's not working brada.. :(

  7. fitztrev
    Posted 8 years ago #

    Is the URL that you are testing in your content indeed long enough? It has to be at least 50 characters.

    You can change that on this line:

    if ( strlen($link) > 50 ) {

  8. olci
    Posted 8 years ago #

    yes i see that.
    i am sure it's enough long.

    i captured a screenshot for my problem.
    please look :


    (at comment, everything OK, but at content it is not working.)
    WP Version : 2.3.3.
    The codes are the same of top what you say.

  9. olci
    Posted 8 years ago #

    have you got any idea ?

  10. fitztrev
    Posted 8 years ago #

    Are they both actually links? If you click them do they do anything? or are they just text?

    The comment one is usually automatically turned into a link while the post one remains just text. That might be what the problem is.

    Make it a link.

  11. olci
    Posted 8 years ago #

    thanks a lot.
    it's OK.

    i forgot to link to url.
    it's working fine.
    thanks :)

Topic Closed

This topic has been closed to new replies.

About this Topic