[Resolved] Modifying Comment Section

Home Forums Support Modifying Comment Section

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #969580
    Melissa

    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?

    #969625
    Leo
    Staff
    Customer Support

    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 🙂

    #969681
    Melissa

    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

    #970213
    Leo
    Staff
    Customer Support

    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.

    #970266
    Melissa

    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!

    #970331
    Leo
    Staff
    Customer Support

    Updated the code above to remove the title.

    Removing the time stamp is quite complicated but Tom explained it in this post:
    https://generatepress.com/forums/topic/removing-date-time-from-comments/#post-250025

    #970363
    Melissa

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

    Thanks!

    #970379
    Leo
    Staff
    Customer Support

    No problem 🙂

    Let me know if you need more info.

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.