• I can change the comments title in my comments.php file. However, whatever title I use is visible not only to another reader but to me too. For example, if the title is the default “Leave a Reply”, not only will another reader see it when leaving a comment, but I’ll see it too when leaving a reply to his or her comment. Is there a way I can change the comments title so that I see only the fields and no title before sending a reply? Taking it one step further, can I remove the name, e-mail and website fields when I’m about to leave a reply, so that I see only the comments field?

    My blog site URL is https://garykrupacpa.com/wordpress

Viewing 9 replies - 1 through 9 (of 9 total)
  • WordPress gives you a nice method for changing up labels, which you can read up on here https://codex.www.ads-software.com/Function_Reference/comment_form. To get you started, take this snippet and add it to your theme’s functions.php and see what happens.

    /**
     * Changing the view for user viewing comment form
     */
    function alter_comments_defaults( $defaults ) {
    	global $post;
    
    		$defaults = array(
    
    			'title_reply'          => '<a name="add-a-comment"></a>' . __( 'add#a#comment', 'text-domain' ) . ' ',
    			'cancel_reply_link'    => __( 'cancel#a#comment', 'text-domain' ),
    			'label_submit'         => __( 'submit#button', 'text-domain' ),
    			'comment_notes_before'	=> '<p class="comment-notes">' . __( 'text#before#comment#box', 'text-domain' ) . '</p>',
    			'comment_field' 		=> '<p class="comment-form-comment"><label for="comment">' .
    			_x( 'comment#box#label', 'text-domain' ) .
    			' * </label><textarea id="comment" name="comment" cols="45" rows="4" aria-required="true"></textarea></p>',
    		);
    
    		return $defaults;
    }
    add_filter( 'comment_form_defaults', 'alter_comments_defaults' );

    If you change nothing other than the strings with hashtags, you should be able to get some decent customizations of labels. Plus, I just chose a few items, on the link above you can find many more. There are also several tutorials out there to help you on your way.

    Thread Starter gkcpa

    (@gkcpa)

    I tried it and I saw how well it works for customizing comment field labels. Thanks for the suggestion, Paul. However, I haven’t been able to get it to display a blank label for the comments form when I click on the reply button, unless the form title is always blank. Now I have three ways of customizing the titles: 1) via comments.php, 2) via functions.php and 3) via the Custom Comment Form Title plugin. I tried a couple of different combinations but haven’t found the right one yet. It looks as though these are static solutions; I’m looking for a dynamic one.

    For starters, if you’re not using a child theme, the plugin will be the safest way to go. A parent theme will be updated periodically and overwrite your changes to comments.php and functions.php.

    If you already have a child theme, then those files will be safe. The next thing I’d say is that you can look to see if there’s an option that will help on the codex page I gave, https://take.ms/UHx7H.

    I’m not sure if this is what concerns you, https://take.ms/uFQVz.

    Thread Starter gkcpa

    (@gkcpa)

    Again thanks, Paul. I’m using a child theme. The option I found on the codex page is comment_form_title, for replying to a comment. When I inserted the recommended code on that page (near page-top) in my comments.php file, nothing happened. The best I can do for displaying the appropriate title is to use the plugin I mentioned above. It won’t do just what I want, but at least it lets me enter a different title with every post. The safest way is to have no comment title, for comments and my replies, but of course then I lose the benefit of having a title for comments.

    Post what you inserted into your comments.php and let’s see if we can figure out why it’s not showing up. Adding a field is tricky because it’s like opening a security hole in your site. It’s probably better if you can use the native functions.

    Thread Starter gkcpa

    (@gkcpa)

    Here you go, Paul:

    <?php comment_reply_link( $args = array(
    ‘title-reply’=>’Your thoughts?’ ); ?>

    If this doesn’t work I’ll use the native functions and plugin, as we both stated.

    OK, so you want to change the link that has the word ‘Reply’? How about you place this in your functions.php

    function alter_comment_reply_link( $link ) {
    	$link = str_replace( 'Reply', 'Alter Reply Link Text', $link );
    	return $link;
    }
    add_filter( 'comment_reply_link', 'alter_comment_reply_link' );

    But if I am understanding you correctly, you should just replace the second string with the text that you want, like:

    function alter_comment_reply_link( $link ) {
    	$link = str_replace( 'Reply', 'Your thoughts?', $link );
    	return $link;
    }
    add_filter( 'comment_reply_link', 'alter_comment_reply_link' );

    Thread Starter gkcpa

    (@gkcpa)

    Thanks, Paul. I tried both functions you sent. At first neither one worked: I received error messages and couldn’t edit the files in WordPress admin. I was probably too tired last night to get it right. Eventually I got the second one to work the way you wrote it. What it did was to replace the reply button with “Your thoughts?” I want that button to say “Reply” and for the comments box title to change to a blank title if I want to reply to a reader comment, and for the comments box title to become “Your thoughts” if a reader will be writing a comment. At present either the comment box title will be either blank or “Your thoughts” no matter who is writing the comment. I think an “if-then” statement would be in order here, but I don’t know enough about WordPress or php to write it. Perhaps we can work on it together, if you have some extra time. I’m sure it would be helpful to someone else besides me.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘How can I change the comments title and fields if I leave a reply?’ is closed to new replies.