WordPress: How to remove “Comments are closed” php code snippet
I came across a project where I had to make a page without any comment box! And no line saying comments off!
After reading a bunch of tutorials online, i finally got down to hacking myself a small snippet for this,
Objective: Remove the comment box/ “Comments are closed” line from the page, where comments were off!
Code:
1. open the functions.php of your current theme and add the following code at the end:
function new_comments_template($attr)
{
global $post;
// please enter the Pages ID's below,
// you can see the ID when you goto edit page in the URL address bar,
// ... domain.com/wp-admin/post.php?post=2&action=edit
// [ the Page ID here is 2 ] //
$no_comment_pages = array(2, 3, 5);
if(in_array($post->ID, $no_comment_pages))
return TEMPLATEPATH."/new_comments.php";
}
add_filter( 'comments_template' , 'new_comments_template');
now look at the line in the above code:
Code:
$no_comment_pages = array(2, 3, 5);
you have to add the IDs of all pages and posts, where you do not want the “comments are closed” line.
2. Create a new file called “new_comments.php”, without the quotes, and add the following line in it:
Code:
<!-- comment hush -->
save it and upload to your current theme folder, both the functions.php and the new_comments.php files.
Thats it! Cheesy
M.
Tags: comment box, comment page, remove comments off, Wordpress
This entry was posted
on Saturday, November 5th, 2011 at 11:04 pm and is filed under Wordpress hacks.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.
WordPress: How to remove “Comments are closed” php code snippet
- November 5th, 2011 by Web Directory | Posted in Wordpress hacks No Comments »WordPress: How to remove “Comments are closed” php code snippet
I came across a project where I had to make a page without any comment box! And no line saying comments off!
After reading a bunch of tutorials online, i finally got down to hacking myself a small snippet for this,
Objective: Remove the comment box/ “Comments are closed” line from the page, where comments were off!
Code:
1. open the functions.php of your current theme and add the following code at the end:
function new_comments_template($attr) { global $post; // please enter the Pages ID's below, // you can see the ID when you goto edit page in the URL address bar, // ... domain.com/wp-admin/post.php?post=2&action=edit // [ the Page ID here is 2 ] // $no_comment_pages = array(2, 3, 5); if(in_array($post->ID, $no_comment_pages)) return TEMPLATEPATH."/new_comments.php"; } add_filter( 'comments_template' , 'new_comments_template');now look at the line in the above code:
Code:
you have to add the IDs of all pages and posts, where you do not want the “comments are closed” line.
2. Create a new file called “new_comments.php”, without the quotes, and add the following line in it:
Code:
save it and upload to your current theme folder, both the functions.php and the new_comments.php files.
Thats it! Cheesy
M.
Tags: comment box, comment page, remove comments off, Wordpress
This entry was posted on Saturday, November 5th, 2011 at 11:04 pm and is filed under Wordpress hacks. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.