WordPress.org

Support

Support » Plugins and Hacks » [Resolved] How Can I Create Auto-Links

[Resolved] How Can I Create Auto-Links

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');

    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: 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');
    
    ?>

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

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

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

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

    i captured a screenshot for my problem.
    please look :

    http://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.

    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.

    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 ‘[Resolved] How Can I Create Auto-Links’ is closed to new replies.