How to disable pingback and trackback on WordPress

Disable pingback and trackback on WordPress

There are several methods to disable pingbacks and trackbacks from your WordPress web site. One is to use a plugin, the other methods are to modify the comment.php and functions.php files inside your theme folder.

I’m not sure why would anyone want to disable pingback and trackback. I still find it useful because I like to see what other are thinking about what I wrote. Yes, there will be tons of spam depending on how popular your site but if you have the latest version of Akisment. You should be able to catch most or all pingback/trackback spam. Also, I like to use trackbacks to refer to different posts.

Method #1
Anyway, here is the first method, probably the easiest way to go about doing things. Use a plugin called Comment Sorter. Just download the plugin and activate. After you activate the plugin, go inside its setting and disable your pingback/trackback accordingly. No need to modify any other files, but you should try the other methods as well to see if it matches your liking.

Method #2
Another method is to edit the comments.php file inside your theme folder.
Open your comments.php file, the start of the Comments Loop look like this:

1
<?php foreach ($comments as $comment) : ?>

To remove pingback/trackback from your theme is to add this code to comments.php right after the start of the loop.

1
<?php if ($comment->comment_type == "pingback" || $comment->comment_type == "trackback") { continue; } ?>

Method #3
The last method is to edit your function.php file inside your theme folder. By modifying your function.php to remove pingback/trackback from your theme help prevent the risk of messing up your theme.

Inside your functions.php file add this code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
add_filter('comments_array', 'filterTrackbacks', 0);
add_filter('the_posts', 'filterPostComments', 0);
//Updates the comment number for posts with trackbacks
function filterPostComments($posts) {
	foreach ($posts as $key => $p) {
		if ($p->comment_count <= 0) { return $posts; }
		$comments = get_approved_comments((int)$p->ID);
		$comments = array_filter($comments, "stripTrackback");
		$posts[$key]->comment_count = sizeof($comments);
	}
	return $posts;
}
//Updates the count for comments and trackbacks
function filterTrackbacks($comms) {
global $comments, $trackbacks;
	$comments = array_filter($comms,"stripTrackback");
	return $comments;
}
//Strips out trackbacks/pingbacks
function stripTrackback($var) {
	if ($var->comment_type == 'trackback' || $var->comment_type == 'pingback') { return false; }
	return true;
}

Get the full tutorial here at weblogtoolscollection.com

More WordPress Tutorials.


Related posts:

Facebook beat Google for the most visited website in the US
How to use Ground Plane with Photoshop CS4
3D lights in Photoshop CS4
Basic Photoshop CS4 animation tutorial
Social media slide next to a website

Write a Comment



(optional)
*