Remove the pingback methods attackers abuse for DDoS and port scanning, while keeping XML-RPC working for Jetpack and the mobile app.
// 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;
} );
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.
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.
Check the response headers of your homepage: there should be no X-Pingback. Jetpack’s connection status should still be fine.