I recently spent a few hours trying to figure out how to add the comments form to a few pages using a StudioPress Genesis template. It’s easy enough to add comments to all pages. But not so easy to add comments to a few specific pages.
As with most things in Genesis, it is very simple once you know the trick. There are two ways to add comments to specific pages.
Method 1
If you have only a few pages, this method is easier. If you already have a lot of pages, Method 2 is more efficient.
- From the WordPress admin menu, select Genesis > Theme Settings.
- Scroll down to the Comments and Trackbacks section and click Enable comments on pages.
Now, comments are turned on for all pages. - Open each page on which you don’t want comments, and under the Discussion section, uncheck Allow Comments.Pages: Page 1 Page 2
Mark says
Thanks for the insight on using the ‘genesis_after_entry’ hook, I was trying to use the ‘genesis_comments’ hook but that’s obviously executed to late.
However you are using the wp_enqueue_scripts hook to remove the action, that hook should only be used to load scripts and stylesheets; you should use the ‘wp’ hook for these kind of functions, so your code would be:
// Remove page comments except for specific pages
add_action( ‘wp’, ‘wnd_remove_comments’ );
function wnd_remove_comments() {
if ( is_page() && (!is_page(58))) {
remove_action( ‘genesis_after_entry’, ‘genesis_get_comments_template’ );
}
}
Pat Fortino says
Hi Mark,
Thanks for the comment. You are correct the
wp
hook works. Also, I figured out thatgenesis_before
works too.and says
You can also use a page template and a
genesis_get_option
filter, like this:<?php
/*
Template Name: Page With Comments
*/
add_filter( 'genesis_pre_get_option_trackbacks_pages', 'custom_page_with_comments' );
add_filter( 'genesis_pre_get_option_comments_pages', 'custom_page_with_comments' );
function custom_page_with_comments() {
return true;
}
genesis();
Pat Fortino says
Thanks. I’ll give that a try. Looks like a more simple solution.