Modify Comment Header?

Hello, is it possible to modify the comment header? I want to change the leave a comment to something else.

Thanks!

url:

Hi There,

Thanks for writing in! Add the following code into your child theme’s functions.php file and then search for the word leave a reply and change according to your requirement. If you don’t have a child theme setup yet, please follow this guide here (https://theme.co/apex/forum/t/setup-how-to-setup-child-themes/57)

function x_ethos_entry_meta() {

    //
    // Author.
    //

    $author = sprintf( ' %1$s %2$s</span>',
      __( 'by', '__x__' ),
      get_the_author()
    );


    //
    // Date.
    //

    $date = sprintf( '<span><time class="entry-date" datetime="%1$s">%2$s</time></span>',
      esc_attr( get_the_date( 'c' ) ),
      esc_html( get_the_date() )
    );


    //
    // Categories.
    //

    if ( get_post_type() == 'x-portfolio' ) {
      if ( has_term( '', 'portfolio-category', NULL ) ) {
        $categories        = get_the_terms( get_the_ID(), 'portfolio-category' );
        $separator         = ', ';
        $categories_output = '';
        foreach ( $categories as $category ) {
          $categories_output .= '<a href="'
                              . get_term_link( $category->slug, 'portfolio-category' )
                              . '" title="'
                              . esc_attr( sprintf( __( "View all posts in: &ldquo;%s&rdquo;", '__x__' ), $category->name ) )
                              . '"> '
                              . $category->name
                              . '</a>'
                              . $separator;
        }

        $categories_list = sprintf( '<span>%1$s %2$s',
          __( 'In', '__x__' ),
          trim( $categories_output, $separator )
        );
      } else {
        $categories_list = '';
      }
    } else {
      $categories        = get_the_category();
      $separator         = ', ';
      $categories_output = '';
      foreach ( $categories as $category ) {
        $categories_output .= '<a href="'
                            . get_category_link( $category->term_id )
                            . '" title="'
                            . esc_attr( sprintf( __( "View all posts in: &ldquo;%s&rdquo;", '__x__' ), $category->name ) )
                            . '"> '
                            . $category->name
                            . '</a>'
                            . $separator;
      }

      $categories_list = sprintf( '<span>%1$s %2$s',
        __( 'In', '__x__' ),
        trim( $categories_output, $separator )
      );
    }


    //
    // Comments link.
    //

    if ( comments_open() ) {

      $title  = apply_filters( 'x_entry_meta_comments_title', get_the_title() );
      $link   = apply_filters( 'x_entry_meta_comments_link', get_comments_link() );
      $number = apply_filters( 'x_entry_meta_comments_number', get_comments_number() );

      $text = ( 0 == $number ) ? __( 'Leave a Comment', '__x__' ) : sprintf( _n( '%s Comment', '%s Comments', $number, '__x__' ), $number );

      $comments = sprintf( '<span><a href="%1$s" title="%2$s" class="meta-comments">%3$s</a></span>',
        esc_url( $link ),
        esc_attr( sprintf( __( 'Leave a comment on: &ldquo;%s&rdquo;', '__x__' ), $title ) ),
        $text
      );

    } else {

      $comments = '';

    }


    //
    // Output.
    //

    if ( x_does_not_need_entry_meta() ) {
      return;
    } else {
      printf( '<p class="p-meta">%1$s%2$s%3$s%4$s</p>',
        $categories_list,
        $author,
        $date,
        $comments
      );
    }

  }

Hope that helps.

Hello, thanks for your response. I do have a child theme. I inserted the code, but it didn’t work. I did it through the editor in the WP dashboard. I made sure the change went through in the file manager. Still no change on the site.

Thanks for your time.

Hi,

Please create file wp-comments.php in wp-content/themes/pro-child/framework/views/ethos

Then add the code below into that file.

<?php

// =============================================================================
// VIEWS/ETHOS/WP-COMMENTS.PHP
// -----------------------------------------------------------------------------
// The area of the page that contains both current comments and the comment
// form. The actual display of comments is handled by a callback to
// x_comment().
// =============================================================================

$commenter     = wp_get_current_commenter();
$req           = get_option( 'require_name_email' );
$asterisk      = ( $req ? '*' : '' );
$asterisk_html = ( $req ? '<span class="required">*</span>' : '' );
$aria_req      = ( $req ? " aria-required='true' required='required'" : '' );

?>

<?php

//
// 1. 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; // 1

?>

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

  <?php if ( have_comments() ) : ?>

    <h2 class="h-comments-title"><span><?php _e( 'Comments' , '__x__' ); ?></span></h2>
    <ol class="x-comments-list">
      <?php
      wp_list_comments( array(
        'callback' => 'x_ethos_comment',
        'style'    => 'ol'
      ) );
      ?>
    </ol>

    <?php if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : ?>
    <nav id="comment-nav-below" class="navigation" role="navigation">
      <h1 class="visually-hidden"><?php _e( 'Comment navigation', '__x__' ); ?></h1>
      <div class="nav-previous"><?php previous_comments_link( __( '&larr; Older Comments', '__x__' ) ); ?></div>
      <div class="nav-next"><?php next_comments_link( __( 'Newer Comments &rarr;', '__x__' ) ); ?></div>
    </nav>
    <?php endif; ?>

    <?php if ( ! comments_open() && get_comments_number() ) : ?>
    <p class="nocomments"><?php _e( 'Comments are closed.' , '__x__' ); ?></p>
    <?php endif; ?>

  <?php endif; ?>

  <?php
  comment_form( array(
    'comment_notes_before' => '',
    'comment_notes_after'  => '',
    'id_submit'            => 'entry-comment-submit',
    'label_submit'         => __( 'Submit' , '__x__' ),
    'title_reply'          => '<span>' . __( 'Leave a Comment</span>' , '__x__' ) . '</span>',
    'fields'               => array(
      'author' =>
        '<p class="comment-form-author">' .
          '<label for="author">' . __( 'Name', '__x__' ) . ' ' . $asterisk_html . '</label> ' .
          '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" placeholder="' . __( 'Your Name', '__x__' ) . ' ' . $asterisk . '" size="30"' . $aria_req . ' />' .
        '</p>',
      'email'  =>
        '<p class="comment-form-email">' .
          '<label for="email">' . __( 'Email', '__x__' ) . ' ' . $asterisk_html . '</label> ' .
          '<input id="email" name="email" type="text" value="' . esc_attr( $commenter['comment_author_email'] ) . '" placeholder="' . __( 'Your Email', '__x__' ) . ' ' . $asterisk . '" size="30"' . $aria_req . ' />' .
        '</p>',
      'url'    =>
        '<p class="comment-form-url">' .
          '<label for="url">' . __( 'Website', '__x__' ) . '</label>' .
          '<input id="url" name="url" type="text" value="' . esc_attr( $commenter['comment_author_url'] ) . '" placeholder="' . __( 'Your Website', '__x__' ) . '" size="30" />' .
        '</p>'
    ),
    'comment_field' => '<p class="comment-form-comment">' .
                         '<label for="comment">' . _x( 'Comment', 'noun', '__x__' ) . '</label>' .
                         '<textarea id="comment" name="comment" cols="45" rows="8" placeholder="' . _x( 'Your Comment *', 'noun', '__x__' ) . '"' . $aria_req . '></textarea>' .
                       '</p>'
  ) );
  ?>

</div>

In the code above find this line 'title_reply' => '<span>' . __( 'Leave a Comment</span>' , '__x__' ) . '</span>',
and change Leave a Comment to any text you like.

Hope this helps.

Brilliant! Yes, this worked. Thank you so much. You guys are the best…

1 Like