Using WordPress ‘is_trackback()’ PHP function

The is_trackback() WordPress PHP function determines whether the query is for a trackback endpoint call.

Usage

if (is_trackback()) {
    // Your custom code here
}

Parameters

  • None

More information

See WordPress Developer Resources: is_trackback()

Examples

Display a custom message for trackback requests

This example will display a custom message when the current request is a trackback.

if (is_trackback()) {
    echo 'This is a trackback request.';
}

Change the page title for trackback requests

This example will change the page title when the current request is a trackback.

function custom_title($title) {
    if (is_trackback()) {
        return 'Trackback Request - ' . $title;
    }
    return $title;
}
add_filter('wp_title', 'custom_title');

Redirect trackback requests to a custom page

This example will redirect trackback requests to a custom page with the slug ‘trackback-info’.

function redirect_trackback_requests() {
    if (is_trackback()) {
        wp_redirect(home_url('/trackback-info/'));
        exit;
    }
}
add_action('template_redirect', 'redirect_trackback_requests');

Display a custom sidebar for trackback requests

This example will display a custom sidebar when the current request is a trackback.

if (is_trackback()) {
    get_sidebar('trackback');
} else {
    get_sidebar();
}

Add custom CSS class to the body for trackback requests

This example will add a custom CSS class to the body tag when the current request is a trackback.

function add_trackback_body_class($classes) {
    if (is_trackback()) {
        $classes[] = 'trackback-request';
    }
    return $classes;
}
add_filter('body_class', 'add_trackback_body_class');