admin管理员组

文章数量:1122846

Anyone know how can I change the comment reply text in wordpress to only reflect on specific pages only and not the whole site?

For example the default text site-wide is “Leave a Reply”. But for some specific pages only, I want the text to read “Leave a Review”.

Is there some code I could use in the comments.php file that would make this work?

Anyone know how can I change the comment reply text in wordpress to only reflect on specific pages only and not the whole site?

For example the default text site-wide is “Leave a Reply”. But for some specific pages only, I want the text to read “Leave a Review”.

Is there some code I could use in the comments.php file that would make this work?

Share Improve this question asked May 8, 2019 at 6:33 dudesonwilldudesonwill 212 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 2

Code is not tested. But theoretically it should work:

add_filter('comment_form_defaults', 'wpse337366_comment_form_modification');
function wpse337366_comment_form_modification($defaults)
{
    // put your condition here
    if( is_page('my-page') || is_singular('my_post_type') )
    {
        $defaults['title_reply'] = __('Leave a Review');
    }
    return $defaults;
}

You can place the code in a plugin or your theme's functions.php.

The code will filter the default texts passed to the comment_form().

Reference

  • comment_form() - WordPress Developer Resources

In your page template, when you call comments template like this, <?php comment_form(); ?> it'll load default theme template. In the page template you need to change comment title, simply call comments template like below,

<?php
      comment_form(array(
      'title_reply' => __( 'Leave a Review' ),
 ));?>

本文标签: How can change wordpress comment reply text for specific pages only