WordPress, enable comments on specific PAGES?

I know how to enable/disable comments on all pages. But how can I enable only a few, WITHOUT USING THE UI. In functions.php I just wanna go

if($this_is_a_page_i_want_comments_on) { enable_comments(); }

enable_comments(); doesn’t exist, this is the part I need help with.

Read More

I could do this using WordPress Admin by allowing comments on all pages, then going to each page and disabling comments where I don’t want them. This would take too long though.

P.S. I’m using Genesis framework.

Related posts

Leave a Reply

2 comments

  1. Simply hook to the comments_open filter 🙂 If you look-up in the source how the comments_open() function works, you’ll notice that the function gets the post in question and then runs it’s reposnse through the comments_open filter. Here’s an example function to override that:

    function my_override_comments_open( $open ) {
        if ( $this_is_a_page_i_want_comments_on ) {
            $open = true;
        }
        return $open;
    }
    add_filter('comments_open', 'my_override_comments_open', 1000);
    

    I assume that you know how you’ll identify the pages that you want to enable comments on – so that’s up to you.

    PP: I don’t know if it will work in Genesis or not(I presume that it should though).

  2. if (is_single('page_name_here') || is_single('other_page')) {
        // Show the comment form here
    }
    

    Not sure if there’s a better way, that’s just my solution!