0

How can i modify the text of number of comments to custom text.

My current display is like this

enter image description here

I want it to be displayed like this.

enter image description here

My commpents.php is

<?php
/**
 * The template for displaying Comments.
 *
 * The area of the page that contains both current comments
 * and the comment form.
 *
 */

/*
 * If the current post is protected by a password and
 * the visitor has not yet entered the password we will
 * return early without loading the comments.
 */
if ( post_password_required() ) {
    return;
}
?>

<div id="comments" class="comments-area">

    <?php // You can start editing here -- including this comment! ?>

    <?php if ( have_comments() ) : ?>
        <h2 class="comments-title">
            <?php

                printf( _nx( 'One comment:', '%1$s Reviews:', get_comments_number(), 'comments title', 'simone' ),
                    number_format_i18n( get_comments_number() )
                                );
            ?>
        </h2>

        <ol class="comment-list">
            <?php
                wp_list_comments( array(
                    'style'      => 'ol',
                    'short_ping' => true,
                                        'avatar_size'=> 50,
                ) );
            ?>
        </ol><!-- .comment-list -->
        <?php if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : // are there comments to navigate through ?>
        <nav id="comment-nav-below" class="comment-navigation clear" role="navigation">
            <h1 class="screen-reader-text"><?php _e( 'Comment navigation', 'simone' ); ?></h1>
            <div class="nav-previous"><?php previous_comments_link( sprintf( '<i class="fa fa-arrow-circle-o-left">%s</i> ', __( 'Older Comments', 'simone' ) ) ); ?></div>
            <div class="nav-next"><?php next_comments_link( sprintf( '<i class="fa fa-arrow-circle-o-right">%s</i> ', __( 'Newer Comments', 'simone' ) ) ); ?></div>
        </nav><!-- #comment-nav-below -->
        <?php endif; // check for comment navigation ?>

    <?php endif; // have_comments() ?>

    <?php
        // If comments are closed and there are comments, let's leave a little note, shall we?
        if ( ! comments_open() && '0' != get_comments_number() && post_type_supports( get_post_type(), 'comments' ) ) :
    ?>
        <p class="no-comments"><?php _e( 'Comments are closed.', 'simone' ); ?></p>
    <?php endif; ?>

    <?php comment_form(); ?>

</div><!-- #comments -->
  • You'll need to modify the comments.php file.. – Abhik Sep 9 '15 at 16:10
  • Is there no way to write a plugin instead – Shahrukh Khan Sep 10 '15 at 2:17
  • That is generally hardcoded in the comments.php file. However, you can replace that with a do_action(); hook, then that can be used to print whatever you like using functions. – Abhik Sep 10 '15 at 5:07
  • could you please give me a fully written function – Shahrukh Khan Sep 10 '15 at 5:08
  • Please edit your question and add the full comments.php code, then I might help you out. – Abhik Sep 10 '15 at 5:09
2

Replace the

<?php
        printf( _nx( 'One comment:', '%1$s Reviews:', get_comments_number(), 'comments title', 'simone' ),
           number_format_i18n( get_comments_number() )
                 );
?>

with

<?php 
    do_action('my_comments_title_hook');
?>

And then ( since the function comments_template() is called within the loop, you can simply ignore the post type check using $post->ID ):

function change_coments_title() {

    if ( get_post_type() == 'post' ) {
        printf( _nx( 'One comment:', '%1$s Comments:', get_comments_number(), 'comments title', 'simone' ), number_format_i18n( get_comments_number() ) );
    } elseif ( get_post_type() == 'review' ) {
        printf( _nx( 'One Review:', '%1$s Reviews:', get_comments_number(), 'comments title', 'simone' ), number_format_i18n( get_comments_number() ) );
    } elseif ( get_post_type() == 'page' ) {
        printf( _nx( 'One Review:', '%1$s Reviews:', get_comments_number(), 'comments title', 'simone' ), number_format_i18n( get_comments_number() ) );
    }
    //Other post types
}
add_action( 'my_comments_title_hook', 'change_coments_title' );

The example function above doesn't change anything for 'posts', but if you are on a CPT called 'reviews', it will do the trick. Do let me know if you want to chenage the title for all post types.

  • it is not working ...... i have a doubt over my_comments_title_hook – Shahrukh Khan Sep 10 '15 at 6:15
  • @ShahrukhKhan, it should work, let me know what post type you are on. – Abhik Sep 10 '15 at 10:22
  • I am on page....the page name is review – Shahrukh Khan Sep 10 '15 at 10:25
  • Okay, edited my answer to change the comments title for 'page' post type. DO let me know if that works. – Abhik Sep 10 '15 at 10:29
  • Glad to know that. – Abhik Sep 10 '15 at 10:31

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.