How to change the comments form title based on post type


You can use the comment_form_defaults filter to change your text based on custom post type. Just check the post type in your filter function.

For example:

add_filter( 'comment_form_defaults', 'my_comment_form_defaults' );
function my_comment_form_defaults( $defaults ) {

     if ( 'my_cool_custom_post_type' == get_post_type() ) {

          $defaults['title_reply'] == 'My Custom Post Type Comment Title';
     return $defaults;

If you need to change various elements of the defaults, see where $defaults is defined just before the filter hook is applied in the source here:

Rather than load a different comments.php based on post type, you could potentially use some switch() or if() logic based on get_post_type() to display differently based on the requested post type.

butlerblog 2 months 2021-04-30T15:48:36-05:00 0 Answers 0 views 0

Leave an answer