Using WordPress ‘add_ping’ PHP filter

The add_ping WordPress PHP filter allows you to modify the new ping URL to add for a specific post.

Usage

add_filter('add_ping', 'your_custom_function');
function your_custom_function($new) {
  // your custom code here
  return $new;
}

Parameters

  • $new (string) – The new ping URL to add.

More information

See WordPress Developer Resources: add_ping

Examples

Changing the ping URL

Modify the ping URL before it’s added to the post:

add_filter('add_ping', 'change_ping_url');
function change_ping_url($new) {
  $new = 'https://example.com/custom-ping-url';
  return $new;
}

Adding a query parameter to the ping URL

Append a query parameter to the ping URL:

add_filter('add_ping', 'add_query_parameter');
function add_query_parameter($new) {
  $new .= '?custom_param=value';
  return $new;
}

Disabling pingbacks for specific domains

Prevent pingbacks for specific domains:

add_filter('add_ping', 'disable_ping_for_domains');
function disable_ping_for_domains($new) {
  $blocked_domains = array('example1.com', 'example2.com');
  $parsed_url = parse_url($new);

  if (in_array($parsed_url['host'], $blocked_domains)) {
    return '';
  }
  return $new;
}

Adding a prefix to the ping URL

Add a custom prefix to the ping URL:

add_filter('add_ping', 'add_prefix_to_ping_url');
function add_prefix_to_ping_url($new) {
  $new = 'custom-prefix-' . $new;
  return $new;
}

Replacing a specific word in the ping URL

Replace a specific word in the ping URL:

add_filter('add_ping', 'replace_word_in_ping_url');
function replace_word_in_ping_url($new) {
  $new = str_replace('old-word', 'new-word', $new);
  return $new;
}