Site logo

Archived topic

Modifying Comment Section

7 replies · Started by Melissa on July 28, 2019

Viewing posts 1–8 of 8

I would like to replace "1 thought on “Title”" with "1 Comment".
I would also like to remove the time but leave the date on the comments.

What is the best way to do this?

Hi there,

Give this PHP snippet a shot:

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(
            '%1$s comment',
	    '%1$s comments',
            $comments_number,
            'comments title',
            'generatepress'
        ) ),
        number_format_i18n( $comments_number ),
	    get_the_title()
    );
} );

Adding PHP: https://docs.generatepress.com/article/adding-php/

Let me know if this helps :)

I got the following error message:

The code snippet you are trying to save produced a fatal error on line 1:

Uncaught Error: Call to undefined function filter() in /home/mkuhnell/public_html/wp-content/plugins/code-snippets/php/admin-menus/class-edit-menu.php(213) : eval()'d code:1 Stack trace: #0 /home/mkuhnell/public_html/wp-content/plugins/code-snippets/php/admin-menus/class-edit-menu.php(213): eval() #1 /home/mkuhnell/public_html/wp-content/plugins/code-snippets/php/admin-menus/class-edit-menu.php(259): Code_Snippets_Edit_Menu->validate_code(Object(Code_Snippet)) #2 /home/mkuhnell/public_html/wp-content/plugins/code-snippets/php/admin-menus/class-edit-menu.php(122): Code_Snippets_Edit_Menu->save_posted_snippet() #3 /home/mkuhnell/public_html/wp-content/plugins/code-snippets/php/admin-menus/class-edit-menu.php(99): Code_Snippets_Edit_Menu->process_actions() #4 /home/mkuhnell/public_html/wp-includes/class-wp-hook.php(286): Code_Snippets_Edit_Menu->load('') #5 /home/mkuhnell/public_html/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters('', Array) #6 /home/mkuhnell/public_html/wp-includes/plugin.php(465): W

Hmm I just tested with Code Snippets without any errors:
https://www.screencast.com/t/aT9ddqqy

Can you double-check if everything is copied and pasted correctly? make sure it's the only snippet n there as well.

OK, I re-pasted and it's working (not crashing). However, now it is showing "1 comment on “Title”" and I want it to not show the "on title". Just the number of comments.

And I want to remove the time stamp on comments.

Thanks so much for helping!

Your code worked perfectly. How silly that it's so hard to remove the time stamp. I'll work on that.

Thanks!

No problem :)

Let me know if you need more info.

This archived topic is closed to new replies.