Using WordPress ‘pingback_useragent’ PHP filter

The pingback_useragent WordPress PHP filter allows you to modify the user agent sent when pinging-back a URL. The user agent is concatenated with ‘ — WordPress/’ and the WordPress version.

Usage

add_filter('pingback_useragent', 'your_custom_function', 10, 5);

function your_custom_function($concat_useragent, $useragent, $pingback_server_url, $pagelinkedto, $pagelinkedfrom) {
  // your custom code here
  return $concat_useragent;
}

Parameters

  • $concat_useragent (string) – The user agent concatenated with ‘ — WordPress/’ and the WordPress version.
  • $useragent (string) – The user agent.
  • $pingback_server_url (string) – The server URL being linked to.
  • $pagelinkedto (string) – URL of the page linked to.
  • $pagelinkedfrom (string) – URL of the page linked from.

More information

See WordPress Developer Resources: pingback_useragent

Examples

Custom user agent

In this example, we change the user agent string to include “My Custom User Agent” instead of the default “WordPress” prefix.

add_filter('pingback_useragent', 'change_user_agent', 10, 5);

function change_user_agent($concat_useragent, $useragent, $pingback_server_url, $pagelinkedto, $pagelinkedfrom) {
  return $useragent . ' -- My Custom User Agent/' . get_bloginfo('version');
}

Remove WordPress version from user agent

This example removes the WordPress version from the user agent string.

add_filter('pingback_useragent', 'remove_wp_version_from_user_agent', 10, 5);

function remove_wp_version_from_user_agent($concat_useragent, $useragent, $pingback_server_url, $pagelinkedto, $pagelinkedfrom) {
  return $useragent . ' -- WordPress';
}

Add theme name to user agent

In this example, we add the current theme’s name to the user agent string.

add_filter('pingback_useragent', 'add_theme_name_to_user_agent', 10, 5);

function add_theme_name_to_user_agent($concat_useragent, $useragent, $pingback_server_url, $pagelinkedto, $pagelinkedfrom) {
  $theme = wp_get_theme();
  return $useragent . ' -- ' . $theme->get('Name') . '/' . get_bloginfo('version');
}

Add site name to user agent

This example adds the site name to the user agent string.

add_filter('pingback_useragent', 'add_site_name_to_user_agent', 10, 5);

function add_site_name_to_user_agent($concat_useragent, $useragent, $pingback_server_url, $pagelinkedto, $pagelinkedfrom) {
  return $useragent . ' -- ' . get_bloginfo('name') . '/' . get_bloginfo('version');
}