3

I'm using Disqus WordPress plugin. When the page is not fully loaded yet, there's only comment count but after that Disqus auto appends the string Comments to that which looks really ugly.

snapshot

From the theme:

    <div class="comment-bubble">
      <a href="<?php the_permalink(); ?>#comments" class="comments-link"><?php comments_number('0', '1', '%'); ?></a>
    </div>

I couldn't figure out what went wrong.

  • 1
    Looks like this is a pure CSS issue and not WordPress related, check the faq. :::: [edit] Is the intention to remove the "comments" text? – brasofilo Feb 22 '13 at 2:18
  • yes, i want to remove the "comments" text. As I understand comments_number('0', '1', '%') will format the comments number as number in format 0 if zero, 1 if one and numbers otherwise. before installing disqus plugin, it works properly. – Tuan Anh Tran Feb 22 '13 at 5:58
  • Go to this page for edit showing comment count text: https://**YOUR_ACCOUNT_NAME**.disqus.com/admin/settings/community/ – Bsevgin Feb 24 '17 at 14:58
2

Not sure how it'll behave with Disqus, but try the following filter:

add_filter( 'comments_number', 'comments_text_wpse_87886', 10, 2 );

function comments_text_wpse_87886 ( $output, $number )
{
    return $number;
}

The original return is $output, and instead we are returning only the number of comments. That filter happens in the following core function, reproduced here if you want to adapt the previous filter hook:

function comments_number( $zero = false, $one = false, $more = false, $deprecated = '' ) {
    if ( !empty( $deprecated ) )
        _deprecated_argument( __FUNCTION__, '1.3' );

    $number = get_comments_number();

    if ( $number > 1 )
        $output = str_replace('%', number_format_i18n($number), ( false === $more ) ? __('% Comments') : $more);
    elseif ( $number == 0 )
        $output = ( false === $zero ) ? __('No Comments') : $zero;
    else // must be one
        $output = ( false === $one ) ? __('1 Comment') : $one;

    echo apply_filters('comments_number', $output, $number);
}

Related: Where to put my code: plugin or functions.php?

  • Thank you. I'm just going for a custom css overflow: hidden; to live with it. Thanks for your reply. – Tuan Anh Tran Feb 22 '13 at 11:30
  • 1
    @TuanAnhTran, so it didn't work? In this case, you shouldn't mark this Answer as "correct"... – brasofilo Feb 22 '13 at 11:34
  • Olps. I thought that one is for closing question. I haven't tried your method yet. – Tuan Anh Tran Feb 22 '13 at 11:55
  • @TuanAnhTran Have you tried it by now? Close to a year passed by... – kaiser Jan 21 '14 at 19:59
  • 1
    This worked for me, tks! – Marcio Duarte Jul 17 '14 at 17:45
2

Basically it's just a request using the WP HTTP API using its functions. Something along the lines of:

$response = wp_remote_get( $disqusURLwithArgs, array( /* API args */ ) );
// Additional checks like wp_remote_retrieve_resonse_code
// or wp_remote_retrieve_response_message
// and is_wp_error( $response )
$content = wp_remote_retrieve_body( $response );
var_dump( $content );

Details for such requests can be found on the Disqus homepage.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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