Site logo

Archived topic

Add Comment Form To Custom Post Type

5 replies · Started by Scott on January 5, 2021

Viewing posts 1–6 of 6

Hi,

I created a CPT using CPT UI plugin. I also created a template page to display the single CPT using the single.php as the template source.

How do you add a comment form to the bottom of a custom post type.

For example, I would like to add the same comment form at the bottom of this post:

https://sites.arizonabirdingtrail.com/hello-world/

to the bottom of this custom post type:

https://sites.arizonabirdingtrail.com/site/fountain-hills-lake/

thanks!

Hi,

Yes, I added a hook with those settings. This displays a link at the bottom of the single CPT, but the link doesn't work.

The link is appending '#respond' to the post title.

Should the comment form be loading in a pop up window, or inline?

You can view the 'Leave a Comment' link at the bottom of the post here:
https://sites.arizonabirdingtrail.com/site/fountain-hills-lake/

-s

Just a followup in case others have a similar issue.

1) Created a custom post type single template by copying single.php -> single-cpt.php

2) Created a custom template by copying content-single.php -> content-cpt.php

In the file single-cpt.php, I had to replace the function call:

generate_do_template_part( 'single' );

with

get_template_part( 'content', ‘cpt’ );

When using the function get_template_part, the comment form was not rendered at the bottom of the single CPT post. Therefore, I added the following snippet to the end of content-cpt.php:

<?php generate_do_comments_template('single'); ?>

Correct me if I’m mistaken, but it appears that generate_do_template_part will load the comment form, but calling get_template_part, will not.

That's correct, you would have to use generate_do_template_part() in order to use the generate_after_do_template_part hook.

Using generate_do_comments_template( 'single' ) works as well :)

This archived topic is closed to new replies.