admin管理员组

文章数量:1278791

Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 3 years ago.

Improve this question

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:

aments-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:

/

Thanks again, Richard

Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 3 years ago.

Improve this question

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:

aments-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/category/all-poet-blogs/richard-grahn/

Thanks again, Richard

Share Improve this question edited Oct 11, 2021 at 18:10 Richard Grahn asked Oct 10, 2021 at 15:40 Richard GrahnRichard Grahn 52 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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.

本文标签: