How to add text to the start of all comments?

You can try the comment_text filter: /** * Prepend text to each comment content. */ add_filter( ‘comment_text’, function( $comment_text ) { $text=”Some text”; return $text . $comment_text; }); if you’re displaying the comment text with: <?php comment_text(); ?>

How can I count only guests comments?

You can use these inside the loop, or in comments.php //The author of current post $author_ID = get_the_author_meta(“ID”); //The current post ID $p_ID = get_the_ID(); //Number of guest comments echo count(get_comments(array( ‘post_id’ => $p_ID, ‘author__not_in’ => array($author_ID) ))); More: https://codex.wordpress.org/Function_Reference/get_comments

How do you change the comment count in the back end posts list, to reflect unapproved comments, rather than all comments?

Add following code in your theme’s functions.php. // To add extra column in column headers add_filter(‘manage_posts_columns’, ‘bs_event_table_head’); function bs_event_table_head( $defaults ) { $defaults[‘pending_comments’] = ‘Pending Comments’; return $defaults; } // To add data in column for each post. add_action( ‘manage_posts_custom_column’, ‘bs_event_table_content’, 10, 2 ); function bs_event_table_content( $column_name, $post_id ) { if ($column_name == ‘pending_comments’) { … Read more

Add back to post link on blank comment post error page

I think ‘pre_comment_on_post’ is a better hook to use, although you’ll have to reproduce some logic from “wp-comments-post.php” to use it, eg: add_action( ‘pre_comment_on_post’, function ( $comment_post_ID ) { $go_back = sprintf( __( ‘<br><a href=”https://wordpress.stackexchange.com/questions/207612/javascript:history.go(-1)”>Back to “%s” Article</a>’ ), get_the_title( $comment_post_ID ) ); // Part-copied from “wp-comments-post.php”, with $go_back tagged onto error strings. $comment_author = … Read more

How to replace default comments with custom HTML?

Note that with the following: add_filter (‘comments_template’, ‘fbcommentbox’, 100); we expect fbcommentbox() to return the path to the new comments template file. The default is the path of comments.php. If you create the fbcommentbox.php file in your theme, then you could try: add_filter( ‘comments_template’, ‘fbcommentbox’, 100); function fbcommentbox( $theme_template ) { // Path to our … Read more

Generate Sub-Comments with WP-CLI [closed]

Currently it is not available in WP CLI. See https://github.com/wp-cli/wp-cli/blob/master/php/commands/comment.php#L136 If you want, you can have your own customized comment generation command. See command cookbook. http://wp-cli.org/docs/commands-cookbook/

if null or int(0) value to 0

There is no use for converting an integer to a string when you just need to display the result or for simple checking against a hardcoded known datatype value. Converting datatypes is only useful when you need to validate values strickly against a certain specific datatype. Your issue is that you do not exactly know … Read more

Add a filter to get_comments_link()

Modifications of the core code are not recommended. Note that the core get_comments_link() function considers two cases of $hash: $hash = get_comments_number( $post_id ) ? ‘#comments’ : ‘#respond’; Also note the second input argument is $post_id. Here’s your modified example: add_filter( ‘get_comments_link’, function( $link, $post_id ) { $hash = get_comments_number( $post_id ) ? ‘#mycomments’ : … Read more