Security PHP Beginner

Disable Pingbacks but Keep XML-RPC

Remove the pingback methods attackers abuse for DDoS and port scanning, while keeping XML-RPC working for Jetpack and the mobile app.

Tested on WordPress 7.1 PHP 8.3 No plugin needed Updated
functions.php 11 lines
// Remove the pingback methods from XML-RPC.
add_filter( 'xmlrpc_methods', function ( array $methods ): array {
	unset( $methods['pingback.ping'], $methods['pingback.extensions.getPingbacks'] );
	return $methods;
} );

// Stop advertising the pingback endpoint.
add_filter( 'wp_headers', function ( array $headers ): array {
	unset( $headers['X-Pingback'] );
	return $headers;
} );

Where to add this

Recommended A code snippets plugin Survives theme changes and is easy to switch off.
Child theme At the end of your child theme's functions.php file.
Must-use plugin As a .php file in wp-content/mu-plugins, starting with <?php.

Always add PHP to a staging site first, or have FTP or file manager access ready, so you can undo it if something goes wrong.

Blocking XML-RPC completely breaks Jetpack and the WordPress mobile app. The part attackers abuse most is pingbacks, which can turn your site into a tool for DDoS attacks on others. This snippet removes only that part.

How it works

The xmlrpc_methods filter lists every method XML-RPC offers. Removing pingback.ping and pingback.extensions.getPingbacks means requests for them get a “method not found” error, while everything else keeps working. The X-Pingback header is removed too.

Things to watch

  • Pingbacks from other blogs to yours will stop arriving. Most sites don’t miss them.
  • Password-guessing through XML-RPC is still possible. Combine with a login limiter, or use the “Block XML-RPC Completely” snippet if you don’t need XML-RPC at all.

How to test it

Check the response headers of your homepage: there should be no X-Pingback. Jetpack’s connection status should still be fine.

This website uses cookies to enhance your browsing experience and ensure the site functions properly. By continuing to use this site, you acknowledge and accept our use of cookies.

Accept All Accept Required Only