DB Error!
RSS Feed Directory Blog Articles Submit Site Popular Sites Contact Us
Web Directory » Blog
|__ WordPress: How to remove “Comments are closed” php code snippet

WordPress: How to remove “Comments are closed” php code snippet

  - November 5th, 2011 by Web Directory | Posted in Wordpress hacks   No Comments »
Email this  Email  |   Print This Post Print This Post     

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: , , ,



Entries (RSS) and Comments (RSS) Blog – Dir.vc :: Web Directory is proudly powered by WordPress - Site By : M-Solutions India