25% off ProSNIPC25OFF

Disable Pingbacks and Trackbacks

Removes the X-Pingback header, strips pingback XML-RPC methods, and disables trackback support on all post types.

PHPby SnipCraft
php
<?php
// Strip X-Pingback response header
add_filter( 'wp_headers', function ( $headers ) {
    unset( $headers['X-Pingback'] );
    return $headers;
} );

// Remove pingback XML-RPC methods
add_filter( 'xmlrpc_methods', function ( $methods ) {
    unset( $methods['pingback.ping'] );
    unset( $methods['pingback.extensions.getPingbacks'] );
    return $methods;
} );

// Disable trackback support on all registered post types
add_action( 'init', function () {
    foreach ( get_post_types() as $post_type ) {
        if ( post_type_supports( $post_type, 'trackbacks' ) ) {
            remove_post_type_support( $post_type, 'trackbacks' );
        }
    }
} );
#hardening#pingback#security#trackback