Wordpress Banner

How to remove WordPress ping backs from your own website

I’ve had the trouble of own ping backs myself. My recent comments is full with self ping backs.

In this blog post I assume you have a Child theme. If not please refer to this blog post first.

  1. Open up your child theme directory and create a new file called functions.php.
  2. If you already have this file in your child-theme directory then please open it.
  3. Add the following snippet of code to your functions.php; and make sure you change the ‘twenty_fifteen’ names to your child-theme name.
<?php 
//Import parent styles the right way and add other stylesheets if necessary.
function twenty_fifteen_child_styles() {
 wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css' );
}
add_action( 'wp_enqueue_scripts', 'twenty_fifteen_child_styles' );
  • Test out if your website is still working as it should.
  • If it does please continue to add this piece of code to your functions.php:
//remove pings to self
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' );

Your functions.php should look something like this now:

<?php 
//Import parent styles the right way and add other stylesheets if necessary.
function YOUR_THEME_NAME_styles() {
 wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css' );
}
add_action( 'wp_enqueue_scripts', 'YOUR_THEME_NAME_styles' );


//remove pings to self
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' );

?>

I’ve actually turned mine off just now ;-). For more help please contact me or comment below.

Published by

Bas Wijdenes

My name is Bas Wijdenes and I work full-time as a Services Engineer. In my spare time I write about the error messages that I encounter during my work. Furthermore, I am currently occupied with Office 365, Azure infrastructure, and PowerShell for automating daily tasks.

Leave a Reply

Your email address will not be published. Required fields are marked *