Closed. This question is off-topic. It is not currently accepting answers.admin管理员组文章数量:1278791
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 questionI'm trying to replace the standard "No Comments" link on blog posts to "Leave a Comment." I'm using the Sinatra theme.
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.
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.
- 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 questionI'm trying to replace the standard "No Comments" link on blog posts to "Leave a Comment." I'm using the Sinatra theme.
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.
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.
- 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 badges1 Answer
Reset to default 1Try 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.
本文标签:
版权声明:本文标题:Change "No Comments" link to "My String" on Blog Post (Find Snippet in Code or use CSS, PHP 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741276010a2369732.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论