Viewing 10 replies - 1 through 10 (of 10 total)
  • 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');
    Thread Starter olci

    (@olci)

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

    any mistake ?

    <?php
    /*
    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: https://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');
    
    ?>
    Thread Starter olci

    (@olci)

    is nobody help me ??
    please brada..
    it’s very important.

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

    Thread Starter olci

    (@olci)

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

    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 ) {

    Thread Starter olci

    (@olci)

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

    i captured a screenshot for my problem.
    please look :

    https://img146.imageshack.us/img146/4656/18482182xb4.png

    (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.

    Thread Starter olci

    (@olci)

    have you got any idea ?
    ??

    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.

    Thread Starter olci

    (@olci)

    ow..
    thanks a lot.
    it’s OK.

    i forgot to link to url.
    it’s working fine.
    thanks ??

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘How Can I Create Auto-Links’ is closed to new replies.