- This topic has 5 replies, 4 voices, and was last updated 1 month ago by
Elvin.
-
AuthorPosts
-
July 23, 2020 at 2:45 am #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?
July 23, 2020 at 3:39 am #1373187David
StaffCustomer SupportHi 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() ); } );
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/July 23, 2020 at 6:27 am #1373368Shami
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?
July 23, 2020 at 6:32 am #1373373David
StaffCustomer SupportYep thats correct.
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/December 23, 2020 at 12:01 am #1591610Jesse
Hi David,
Is there a way to improve upon this snippet so it will show “1 comment” instead of “1 comments” if there is only one comment?
Thanks!
December 23, 2020 at 12:45 am #1591636Elvin Customer Support
Hi Jesse,
You’ll have to set the values inside _nx() checking the comment count:
Something like this should work.
add_filter( 'generate_comment_form_title', function(){ $comments_number = get_comments_number(); return sprintf( esc_html( /* translators: 1: number of comments, 2: post title */ _nx( '%1$s Comment on “%2$s”', '%1$s Comments on “%2$s”', $comments_number, 'comments title', 'generatepress' ) ), number_format_i18n( $comments_number ), get_the_title() ); });
Simply remove
on “%2$s”
if you don’t want the title.A wise man once said:
"Have you cleared your cache?" -
AuthorPosts
- You must be logged in to reply to this topic.