- Web templates
- E-commerce Templates
- CMS & Blog Templates
- Facebook Templates
- Website Builders
Monstroid. How to add comments to custom posts
November 18, 2015
This tutorial shows how to enable comments for custom posts in Monstroid themes.
Monstroid. How to add comments to custom postsYou’ll learn how to enable comments for Team posts in this tutorial.
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.
-
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 ); } }
-
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.
-
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:
-
Refresh front-end with Ctrl/Cmd+F5 to see the changes. The Comment form will appear on a page:
Feel free to check the detailed video tutorial below:
Monstroid. How to add comments to custom posts