Categories

Featured templates

Monstroid. How to add comments to custom posts

Stacy Martin November 18, 2015
Rating: 5.0/5. From 2 votes.
Please wait...

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 http://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
This entry was posted in Monstroid Tutorials, WordPress Tutorials and tagged comments, custom, Monstroid, post. Bookmark the permalink.

Submit a ticket

If you are still unable to find a sufficient tutorial regarding your issue please use the following link to submit a request to our technical support team. We'll provide you with our help and assistance within next 24 hours: Submit a ticket