• Resolved dropshot

    (@dropshot)


    I’m trying to change the comment_author_url_link output. I want to display the comment author url, but only if one exists.

    <?php comment_author_url_link('linktext', 'before', 'after'); ?>

    This one is supposed to display the url id one is provided. So if I use:

    <?php comment_author_url_link('', 'Website:', ''); ?>

    “Website:” is still displayed even if a url is not provided. And if empty it still generates a anchor tag.

    <a rel="external" href="" ></a>

    Is there someway to edit this output?

Viewing 10 replies - 1 through 10 (of 10 total)
  • Moderator Jose Castaneda

    (@jcastaneda)

    THEME COFFEE MONKEY

    You can try adding a filter:

    add_filter( 'get_comment_author_url_link', 'custom_comment_author_url_link' );
    function custom_comment_author_url_link( $linktext, $before = '', $after = '' ){
        /** your code goes here **/
    }

    The core function is in the comment-template file.

    Thread Starter dropshot

    (@dropshot)

    Thank you Jose.

    I found the comment-template file. I just don’t know how to edit it.

    The adding a filter advise is a big help. But still I don’t know how to edit it. I’m not sure what the original if statement does.

    if ( '/' == substr($display, -1) )
    	        $display = substr($display, 0, -1);
    	        $return = "$before<a href='$url' rel='external'>$display</a>$after";

    Another push in the right direction please…

    Moderator Jose Castaneda

    (@jcastaneda)

    THEME COFFEE MONKEY

    No, do not edit the core files.

    What you do is add the filter in your themes functions file or plugin.

    Something like:

    add_filter( 'get_comment_author_url_link', 'custom_comment_author_url_link' );
    function custom_comment_author_url_link( $linktext, $before = '', $after = '' ){
        $url = get_comment_author_url();
        if ( $url == '' ) return;
    	$display = ( $linktext != '' ) ? $linktext : $url;
    	$display = str_replace( 'http://www.', '', $display );
    	$display = str_replace( 'http://', '', $display );
    	if ( '/' == substr( $display, -1) )
    		$display = substr( $display, 0, -1);
    	return = "$before<a href='$url' rel='external'>$display</a>$after";
    }

    Thread Starter dropshot

    (@dropshot)

    Ok, I might not be clear enough. Sorry for that.

    Yes, I know I should not edit core files. That’s why I was stuck.

    I’ll try adding your filter.

    Thanks a lot Jose!

    Thread Starter dropshot

    (@dropshot)

    That filter unfortunately white-screens the site…

    Any other suggestions?

    Moderator Jose Castaneda

    (@jcastaneda)

    THEME COFFEE MONKEY

    Forgot to take out the = after return. Sorry. I feel really bad I didn’t respond sooner. 🙁

    Thread Starter dropshot

    (@dropshot)

    No need to feel bad!

    I will try this later.

    Thank you!

    Thread Starter dropshot

    (@dropshot)

    Ok.

    I’ve tried it now and this code does two things.

    As we were attempting to do it doesn’t produce the empty anchor tag. Thats great!

    But. Something in the code makes the author url a link inside my site.

    Instead of
    authorurl.com

    the link is
    mysite.com/authorurl.com

    I can’t really figure out what line does what. Help please.

    Thread Starter dropshot

    (@dropshot)

    Update:

    I deleted

    $display = str_replace( 'http://www.', '', $display );
    $display = str_replace( 'http://', '', $display );

    So now, the correct links are returned.

    But… When there is no url no anchor is returned. But when there is a url the anchor is returned twice with different output…

    Like this

    <a rel="external" href="http://authorurl.com"> </a>
    <a rel="external" href="http://authorurl.com">authorurl.com</a>
    Thread Starter dropshot

    (@dropshot)

    Ok. Think I got it now. This is what I ended up with.

    add_filter( 'get_comment_author_url_link', 'custom_comment_author_url_link' );
    function custom_comment_author_url_link( $linktext, $before = '', $after = '' ){
        $url = get_comment_author_url();
        if ( $url == '' ) return;
    	$display = ( $linktext != '' ) ? $linktext : $url;
    		if ( '/' == substr( $display, -1) )
    		$display = substr( $display, 0, -1);
    	return "$display";
    }
Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Custom comment_author_url_link output’ is closed to new replies.