If this tutorial is not what you were looking for, you still have any questions, suggestions or concerns - feel free to let us know. Please help us to serve you better!

Your Name

Your Email

Your Message (required)

captcha

Featured templates

Monstroid. How to add comments to custom posts

This tutorial shows how to enable comments for custom posts in Monstroid themes.

Monstroid. How to add comments to custom posts

You’ll learn how to enable comments for Team posts in this tutorial.

  1. In order to enable comments for custom posts, you’ll need to check the Allow comments option on Edit Post page. When this option is missing on the Editor page, additional code is required.

  2. Copy the code required for enabling comments from https://gist.github.com/cheh/ec191fce0d397e10f77f or copy it from below:

     // Adds a `comments` support feature for a team single post.
      add_filter( 'cherry_team_post_type_args', 'cherry_child_add_comments_support' );
      function cherry_child_add_comments_support( $args ) {
     if ( ! empty( $args['supports'] ) ) {
      $args['supports'][] = 'comments';
      }
     return $args;
      }
    /**
      * Loads the comment template in single team post.
      *
      * @see do_action( 'cherry_post_after' ) - hook in plugins/cherry-XXXX/templates/single-XXXX.php file.
      */
      add_action( 'cherry_post_after', 'cherry_child_load_comments_template', 25 );
      function cherry_child_load_comments_template() {
      $post_type = get_post_type();
    if ( 'team' !== $post_type ) {
      return;
      }
     if ( ! is_singular( $post_type ) ) {
      return;
      }
     if ( comments_open() || get_comments_number() ) {
      comments_template( '/templates/comments.php', true );
      }
      }
    
      
  3. Next, navigate to Appearance -> Editor, under themeXXXXX select functions.php file to edit. Paste the code required at the bottom of the functions.php file.

  4. To check the changes, go to the Team tab of admin panel, open any post and scroll it down to find the Allow Comments option. Check it and update the post:

    Monstroid. How to add comments to custom posts-1

  5. Refresh front-end with Ctrl/Cmd+F5 to see the changes. The Comment form will appear on a page:

    Monstroid. How to add comments to custom posts-2

Feel free to check the detailed video tutorial below:

Monstroid. How to add comments to custom posts