[Support request] How to change ‘X’ thoughts on ‘post title’ in comment section

Home Forums Support How to change ‘X’ thoughts on ‘post title’ in comment section

  • This topic has 3 replies, 2 voices, and was last updated 2 months ago by David.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1373134
    Shami

    I just wish If I could change the title of the comment section.

    Instead of: ‘X’ thoughts on ‘post title’

    I want to make it: Reader Comments (count)

    Is there any easy fix for it?

    #1373187
    David
    Staff
    Customer Support

    Hi there,

    try this PHP Snippet:

    add_filter( 'generate_comment_form_title', function() {
        $comments_number = get_comments_number();
    
        return sprintf( // WPCS: XSS OK.
            /* translators: 1: number of comments */
            esc_html( _nx(
                'Reader Comments %1$s',
    	    'Reader Comments %1$s',
                $comments_number,
                'comments title',
                'generatepress'
            ) ),
            number_format_i18n( $comments_number ),
    	get_the_title()
        );
    } );
    #1373368
    Shami

    Thanks, David. It worked perfectly.

    There is one thing though: The above code doesn’t put brackets around the comment’s count. So I placed them myself.

    I replaced this:

    /* translators: 1: number of comments */
    esc_html( _nx(
    ‘Reader Comments %1$s’,
    ‘Reader Comments %1$s’,
    $comments_number,
    ‘comments title’,
    ‘generatepress’
    ) ),

    With this:

    /* translators: 1: number of comments */
    esc_html( _nx(
    ‘Reader Comments (%1$s)’,
    ‘Reader Comments (%1$s)’,
    $comments_number,
    ‘comments title’,
    ‘generatepress’
    ) ),

    It works fine now. Did I do it right?

    #1373373
    David
    Staff
    Customer Support
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.