is_trackback()
Checks if the current request is a trackback page request.
The processing of trackback requests is handled by the file wp-trackback.php.
When might it be useful?
Checking the request may be useful when, for example, you are connecting to the main request and need to make some changes to it, only for pings coming from other sites.
This task is extremely rare.
How does it work?
When you write content for a post and insert links into it, WordPress tries to notify the sites (domains of external links) that you are referencing them. This notification is called:
- Trackback or Pingback for the one receiving this notification.
- Ping for the one sending this notification.
In this case, WordPress, on which the post with links is published, sends a POST request to the file wp-trackback.php. There the WordPress core is loaded and the parameter tb=1 is set in the main request.
require_once( dirname( __FILE__ ) . '/wp-load.php' ); wp( [ 'tb' => '1' ] );
The parameter tb sets the property WP_Query::is_trackback = true - this means that the conditional tag is_trackback() will trigger, which in turn means that this is a trackback (pingback) request. Then, the transmitted POST data is checked, and if everything is in order, a ping is added to the comments table, notifying you that your article has been referenced. The comment type in the database is specified as pingback: comment_type = pingback.
You can manage the sending and receiving of pings in the discussion settings:

Read also: How notifications (pings) work in WordPress
No Hooks.
Returns
true|false. true/false
Usage
if( is_trackback() ){
// ping request
}
Examples
#1 Set the HTTP response header for the trackback request
add_action( 'template_redirect', function(){
if( is_trackback() ){
header( 'X-Disabled-Reason: trackback' );
}
} );
Notes
- Global. WP_Query. $wp_query WordPress Query object.
Changelog
| Since 1.5.0 | Introduced. |
is_trackback() is trackback code WP 6.9
function is_trackback() {
global $wp_query;
if ( ! isset( $wp_query ) ) {
_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' );
return false;
}
return $wp_query->is_trackback();
}