Home / admin / Disable self pings with pre_ping hook
  • How to Disable self pings with pre_ping hook

    disable-self-pings-with-pre_ping-hook

    Adding this snippet to the functions.php of your wordpress theme will disable self pings to your blog.

    ( click code to copy )

    wordpress snippet : PHP

    <>
    function no_self_ping( &$links ) {
        $home = get_option( 'home' );
        foreach ( $links as $l => $link )
            if ( 0 === strpos( $link, $home ) )
                unset($links[$l]);
    }
    add_action( 'pre_ping', 'no_self_ping' );
    

    ( WordPress codex functions, hooks, in this snippet. )

    home, add_action, get_option,
  • Guest

    this doesn’t work, error:
    Fatal error: Cannot redeclare no_self_ping()

    • Hi That error means you have the function no_self_ping in your functions.php already.