Using WordPress ‘pingback_ping_source_uri’ PHP filter

The pingback_ping_source_uri WordPress PHP filter allows you to modify the pingback source URI.

Usage

add_filter('pingback_ping_source_uri', 'my_custom_pingback_source_uri', 10, 2);

function my_custom_pingback_source_uri($pagelinkedfrom, $pagelinkedto) {
    // Your custom code here
    return $pagelinkedfrom;
}

Parameters

  • $pagelinkedfrom (string) – URI of the page linked from.
  • $pagelinkedto (string) – URI of the page linked to.

More information

See WordPress Developer Resources: pingback_ping_source_uri

Examples

Change the source URI

This example changes the pingback source URI to a custom value.

add_filter('pingback_ping_source_uri', 'change_pingback_source_uri', 10, 2);

function change_pingback_source_uri($pagelinkedfrom, $pagelinkedto) {
    $custom_source = 'https://example.com/custom-source/';
    return $custom_source;
}

Add a query parameter to the source URI

This example adds a query parameter to the source URI.

add_filter('pingback_ping_source_uri', 'add_query_param_to_source_uri', 10, 2);

function add_query_param_to_source_uri($pagelinkedfrom, $pagelinkedto) {
    $pagelinkedfrom .= '?utm_source=pingback';
    return $pagelinkedfrom;
}

Replace the source domain

This example replaces the source domain with a different domain.

add_filter('pingback_ping_source_uri', 'replace_source_domain', 10, 2);

function replace_source_domain($pagelinkedfrom, $pagelinkedto) {
    $new_domain = 'https://new-domain.com';
    $source_uri = str_replace('https://old-domain.com', $new_domain, $pagelinkedfrom);
    return $source_uri;
}

Remove certain parameters from the source URI

This example removes a specific query parameter from the source URI.

add_filter('pingback_ping_source_uri', 'remove_query_param_from_source_uri', 10, 2);

function remove_query_param_from_source_uri($pagelinkedfrom, $pagelinkedto) {
    $parsed_url = parse_url($pagelinkedfrom);
    parse_str($parsed_url['query'], $query_params);
    unset($query_params['remove_me']);
    $new_query = http_build_query($query_params);
    $new_url = "{$parsed_url['scheme']}://{$parsed_url['host']}{$parsed_url['path']}?{$new_query}";
    return $new_url;
}

Set the source URI to the linked-to page’s URL

This example sets the pingback source URI to the same value as the linked-to page’s URL.

add_filter('pingback_ping_source_uri', 'set_source_uri_to_linked_to', 10, 2);

function set_source_uri_to_linked_to($pagelinkedfrom, $pagelinkedto) {
    return $pagelinkedto;
}