Support » Plugins » Hacks » Setting comment_notes_after in comment_form

  • Resolved Ate Up With Motor



    I’m trying to figure out how to add a piece of reminder text to my WordPress site’s comment form. I can get it to work by copying my parent theme’s comments.php file and inserting the text here:

    <?php comment_form(array('comment_notes_after' => '')); ?>

    It seems like I should be able to set the comment_notes_after argument with a filter hook from the child theme’s functions.php file, but I’m still trying to get my head around the filter hook concept and I can’t figure out how to do it.

    I know I need to define a function and then use add_filter to hook that filter to the comment_form function, but I’m not grasping at all what the function needs to be.

    Sorry if this is obtuse — I’m not a programmer and a lot of this is entirely new to me.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Moderator t-p


    Try adding this to your theme’s functions.php, and see if it works for you:

    add_action('comment_form', 'my_reminder_note');
    function my_reminder_note() {
    	if (is_single()) {
    	echo '<div class="YOUR CLASS"> ';	echo  ' YOUR REMINDER NOTE');
    	echo '</div>';

    That gives me a syntax error; something about the echo statements isn’t punctuated right, I think.

    Also, I don’t know why it would need an if statement. Basically, I want to add some text that will appear as part of the comment form (above the submit button, which is why I was looking at comment_notes_after) any time comment_form is called.

    Okay, I figured out the syntax error and got that to work. I was hoping to add the notice above the submit button (which I’m able to do by setting the comment_notes_after argument for comment_form, although as mentioned that involved hacking or replacing a theme file), so it’s not exactly what I’m after, but it will probably suffice.

    Moderator bcworkz


    Glad you got it working.

    Not essential, but if you’re interested, adding a filter hook to a child theme’s functions.php file isn’t normally considered hacking a theme (in the bad sense of something to be avoided) Child themes were implemented exactly for this sort of thing.

    Some commercial themes are actually child themes, so in that case (or if it just makes more sense conceptually) you could create a simple plugin to contain your filter hook code. Creating a plugin is nothing more than putting a particularly formatted comment on your code page and placing it in a folder under the plugins directory.

    I know that adding a filter hook is not considered theme-hacking; my point was that I couldn’t figure out any way to make the change I wanted without hacking theme files.

    Besides not wanting to hack or replace theme files, the reason I was hoping to handle it this way was that I was really hoping I could figure out how to create a simple filter hook so that I can do so again later. I grasp what the filters do and understand approximately how a filter hook would need to work to do what I wanted, but I’m just not familiar enough with PHP or WordPress functions to make it work.

    It doesn’t seem like a plugin (even a simple one) should be necessary for something as simple as setting the value of a single argument for comment_form() each time that function is called, but maybe I just don’t get it…

    In any case, the action hook gets the job done, so that’s definitely a step in the right direction. Thanks!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Setting comment_notes_after in comment_form’ is closed to new replies.