Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I can change label of comments by altering Comment(s) from parameter of following function: comments_popup_link('No Comments;', '1 Comment;', '% Comments;'); But, seems that title attribute is returned from core modules. Suggest me to alter title attribute without editing core modules.

share|improve this question
1  
Have you tried using localization to change that? An .mo file doesn't need to have more than one string in it... You could create a custom .mo file that "translates" the string 'Comment on %s' to whatever you want it to say... –  goldenapples Aug 20 '11 at 17:55

1 Answer 1

up vote 2 down vote accepted

If you look into the function comments_popup_link() you will see the following code at the end:

$title = the_title_attribute( array('echo' => 0 ) );

echo apply_filters( 'comments_popup_link_attributes', '' );

echo ' title="' . esc_attr( sprintf( __('Comment on %s'), $title ) ) . '">';
comments_number( $zero, $one, $more );
echo '</a>'; // last line

Note the call to __(), the translation function. We can filter 'gettext' to change the result. Since we do not want to run our filter on every translation – that would be too slow – we start the filter when the hook 'comments_popup_link_attributes' is called:

add_filter( 'comments_popup_link_attributes', 't5_cclta_init' );

function t5_cclta_init( $attrs )
{
    add_filter( 'gettext', 't5_cclta_change_title', 10, 3 );
    return $attrs;
}

Now we need just the real filter function:

function t5_cclta_change_title( $translated, $text, $domain )
{
    remove_filter( current_filter(), __FUNCTION__, 10 );

    if ( 'default' === $domain && 'Comment on %s' === $text )
        return 'Talk about %s';

    return $translated;
}

And now the title attribute says: Talk about The Post Title.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.