Site logo

Archived topic

Adding a paragraph with a link to a comment policy under comment title

10 replies · Started by Dan on March 10, 2021

Viewing posts 1–11 of 11

I've changed the comment form title with the code below.

add_filter( 'generate_leave_comment', function() {
    return 'Comment on the article';
} );

Now I want to add the following paragraph code just under that but I don't quite know how.

"<p class='comment-policy'>Thanks for choosing to comment on this article. A name and email address are required to post a comment. The email address is not publicly visible or shared. Please keep in mind that comments are moderated according to our <a href='https://www.frontstretch.com/comment-policy/'>comment policy</a>.</p>"

So I could use the same general idea that I used for the title to add this in functions.php?

add_filter( 'generate_below_comments_title', function() {
    return "<p class='comment-policy'>Thanks for choosing to comment on this article. A name and email address are required to post a comment. The email address is not publicly visible or shared.  Please keep in mind that comments are moderated according to our <a href='https://www.frontstretch.com/comment-policy/'>comment policy</a>.</p>";
} );

Yup - but you will need to use add_action for hooks instead of add_filter.

Thanks, Leo.

So:

add_action( 'generate_below_comments_title', function() {
    return "<p class='comment-policy'>Thanks for choosing to comment on this article. A name and email address are required to post a comment. The email address is not publicly visible or shared.  Please keep in mind that comments are moderated according to our <a href='https://www.frontstretch.com/comment-policy/'>comment policy</a>.</p>";
} );

Hi Dan,

Try to change returnto print.
Let me know :)

Ok, I've got

add_action( 'generate_below_comments_title', function() {
    print "<p class='comment-policy'>Thanks for choosing to comment on this article. A name and email address are required to post a comment.
    The email address is not publicly visible or shared.
    Please keep in mind that comments are moderated according to our <a href='https://www.frontstretch.com/comment-policy/'>comment policy</a>.</p>";
} );

in my child theme functions.php but the paragraph doesn't show up.

Here's a link to one of the articles on the site. https://www.frontstretch.com/2021/03/10/ross-chastain-moose-fraternity-partners-for-several-cup-events

So obviously I'm missing something here.

I changed the code above to add_action( 'generate_before_comments', function() { instead of
add_action( 'generate_below_comments_title', function() and that gets the code on the page, although it's above the contents title instead of below it, like I was originally trying to do. I'm not sure why this worked but below comments title did not.

I tested this on my local site, and it works.

add_action( 'generate_below_comments_title', function() {
    print "<p class='comment-policy'>Thanks for choosing to comment on this article. A name and email address are required to post a comment. The email address is not publicly visible or shared.  Please keep in mind that comments are moderated according to our <a href='https://www.frontstretch.com/comment-policy/'>comment policy</a>.</p>";
} );

https://www.screencast.com/t/F1n2g7wf

Just make sure you don't have other functions conflict with this one.

Thanks for testing. I must have a conflict somewhere. In any case I'm calling this resolved since I have a solution.

No problem :)
As long as it's working for you!

This archived topic is closed to new replies.