0

I'm trying to replace the standard "No Comments" link on blog posts to "Leave a Comment." I'm using the Sinatra theme.

  1. I can't find the code that creates this text. So, I'm wondering where it is. That would be simple to replace in my child theme.

  2. I've tried CSS using pseudo-elements like this to no avail:

a.comments-link:after { content: 'Leave a Comment'; }

That adds the text in the right place but doesn't remove the "No Comments" text. It also, if successful, would wipe out the "1 Comment" text on posts with a comment.

  1. I have no idea how to do this in PHP. Any thoughts would be appreciated.

Thank you for any help you can offer with this.


This is what my functions.php file looks like now. Hope this helps a bit.


/**
 * Redefine sinatra_excerpt function. This works to change the 
 *excerpt to a full post but for some reason, doesn't remove the 
 *"Read More" link.
 * 
 */
function sinatra_excerpt( $more = null, $length = null ) {
    the_content();
}

/*
 * @param string $output A translatable string formatted based on whether the count
 *                       is equal to 0, 1, or 1+.
 * @param int    $number The number of post comments.
 * @return string $output
 * This doesn't work at all.
 */
function richards_no_comment_string( $output, $number ){

    if( $number === 0 ){
        
        $output = __( 'Leave a Comment' );
    }

    return $output;
}
add_filter('comments_number', 'richards_no_comment_string', 20, 2);

And here's a link to the page in question:

https://poets.drifting-sands-haibun.org/category/all-poet-blogs/richard-grahn/

Thanks again, Richard

1

Try this. You can add this snippet in a child theme functions.php file.

Replace "Your No Comments String" with whatever you want.

/*
 * @param string $output A translatable string formatted based on whether the count
 *                       is equal to 0, 1, or 1+.
 * @param int    $number The number of post comments.
 * @return string $output
 */
function richards_no_comment_string( $output, $number ){

    if( $number === 0 ){
        
        $output = __( 'Your No Comments String' );
    }

    return $output;
}
add_filter('comments_number', 'richards_no_comment_string', 20, 2);

For the free Sinatra theme, which uses a theme specific function to output that text, the customization would be to add to the child theme this function:

    function sinatra_entry_meta_comments() {
    
            $icon = sinatra()->icons->get_meta_icon( 'comments', sinatra()->icons->get_svg( 'message-square', array( 'aria-hidden' => 'true' ) ) );
    
            if ( ! post_password_required() && ( comments_open() || get_comments_number() ) ) {
                echo '<span class="comments-link">';
    
                comments_popup_link( wp_kses_post( $icon ) . esc_html__( 'Leave a Comment', 'sinatra' ), wp_kses( $icon, sinatra_get_allowed_html_tags( 'post' ) ) . esc_html__( '1 Comment', 'sinatra' ), wp_kses( $icon, sinatra_get_allowed_html_tags( 'post' ) ) . esc_html__( '% Comments', 'sinatra' ), 'comments-link' );
    
                echo '</span>';
    }
}

Tested and confirmed working. enter image description here

10
  • 1
    I would advise against using a plugin such as code snippets for security reasons
    – Tom J Nowell
    Oct 10 '21 at 18:14
  • Thanks, @Tami, That doesn't work even though it should. I had a similar problem when trying to get rid of the read more link using functions. I suggest the culprit may be related to the following . . . 1. The "blog" in question is actually generated from a link in the main menu that generates posting in a given category. There will be many of these eventually. 2. I'm using a function that makes each post a full post rather than an excerpt. Even that function is only partially working. Could one of these be the trouble? See the original post question above, I've added more info. Oct 11 '21 at 18:19
  • @RichardGrahn Any chance you have a link at hand where to see the code rendering? A direct look will likely help figure this out.
    – Tami
    Oct 11 '21 at 22:07
  • @Tami There's a link at the bottom of the origin post in this thread. Let me know it that's what you're looking for. Thanks. Also, there's a code snippet in the original post. Oct 11 '21 at 23:36
  • @RichardGrahn I am updating my answer, please check it and let me know if this works now?
    – Tami
    Oct 12 '21 at 0:11

Not the answer you're looking for? Browse other questions tagged or ask your own question.