Title: discover_pingback_server_uri
Published: April 25, 2014
Last modified: February 24, 2026

---

# discover_pingback_server_uri( string $url, string $deprecated ): string|false

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/discover_pingback_server_uri/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/functions/discover_pingback_server_uri/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/discover_pingback_server_uri/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/discover_pingback_server_uri/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/discover_pingback_server_uri/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/discover_pingback_server_uri/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/discover_pingback_server_uri/?output_format=md#wp--skip-link--target)

Finds a pingback server URI based on the given URL.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/discover_pingback_server_uri/?output_format=md#description)󠁿

Checks the HTML for the rel=”pingback” link and X-Pingback headers. It does a check
for the X-Pingback headers first and returns that, if available.
The check for the
rel=”pingback” has more overhead than just the header.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/discover_pingback_server_uri/?output_format=md#parameters)󠁿

 `$url`stringrequired

URL to ping.

`$deprecated`stringrequired

Not Used.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/discover_pingback_server_uri/?output_format=md#return)󠁿

 string|false String containing URI on success, false on failure.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/discover_pingback_server_uri/?output_format=md#source)󠁿

    ```php
    function discover_pingback_server_uri( $url, $deprecated = '' ) {
    	if ( ! empty( $deprecated ) ) {
    		_deprecated_argument( __FUNCTION__, '2.7.0' );
    	}

    	$pingback_str_dquote = 'rel="pingback"';
    	$pingback_str_squote = 'rel=\'pingback\'';

    	/** @todo Should use Filter Extension or custom preg_match instead. */
    	$parsed_url = parse_url( $url );

    	if ( ! isset( $parsed_url['host'] ) ) { // Not a URL. This should never happen.
    		return false;
    	}

    	// Do not search for a pingback server on our own uploads.
    	$uploads_dir = wp_get_upload_dir();
    	if ( str_starts_with( $url, $uploads_dir['baseurl'] ) ) {
    		return false;
    	}

    	$response = wp_safe_remote_head(
    		$url,
    		array(
    			'timeout'     => 2,
    			'httpversion' => '1.0',
    		)
    	);

    	if ( is_wp_error( $response ) ) {
    		return false;
    	}

    	if ( wp_remote_retrieve_header( $response, 'X-Pingback' ) ) {
    		return wp_remote_retrieve_header( $response, 'X-Pingback' );
    	}

    	// Not an (x)html, sgml, or xml page, no use going further.
    	if ( preg_match( '#(image|audio|video|model)/#is', wp_remote_retrieve_header( $response, 'Content-Type' ) ) ) {
    		return false;
    	}

    	// Now do a GET since we're going to look in the HTML headers (and we're sure it's not a binary file).
    	$response = wp_safe_remote_get(
    		$url,
    		array(
    			'timeout'     => 2,
    			'httpversion' => '1.0',
    		)
    	);

    	if ( is_wp_error( $response ) ) {
    		return false;
    	}

    	$contents = wp_remote_retrieve_body( $response );

    	$pingback_link_offset_dquote = strpos( $contents, $pingback_str_dquote );
    	$pingback_link_offset_squote = strpos( $contents, $pingback_str_squote );

    	if ( $pingback_link_offset_dquote || $pingback_link_offset_squote ) {
    		$quote                   = ( $pingback_link_offset_dquote ) ? '"' : '\'';
    		$pingback_link_offset    = ( '"' === $quote ) ? $pingback_link_offset_dquote : $pingback_link_offset_squote;
    		$pingback_href_pos       = strpos( $contents, 'href=', $pingback_link_offset );
    		$pingback_href_start     = $pingback_href_pos + 6;
    		$pingback_href_end       = strpos( $contents, $quote, $pingback_href_start );
    		$pingback_server_url_len = $pingback_href_end - $pingback_href_start;
    		$pingback_server_url     = substr( $contents, $pingback_href_start, $pingback_server_url_len );

    		// We may find rel="pingback" but an incomplete pingback URL.
    		if ( $pingback_server_url_len > 0 ) { // We got it!
    			return $pingback_server_url;
    		}
    	}

    	return false;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/comment.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/comment.php#L2921)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/comment.php#L2921-L2997)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/discover_pingback_server_uri/?output_format=md#related)󠁿

| Uses | Description | 
| [wp_get_upload_dir()](https://developer.wordpress.org/reference/functions/wp_get_upload_dir/)`wp-includes/functions.php` |

Retrieves uploads directory information.

  | 
| [wp_safe_remote_head()](https://developer.wordpress.org/reference/functions/wp_safe_remote_head/)`wp-includes/http.php` |

Retrieves the raw response from a safe HTTP request using the HEAD method.

  | 
| [wp_remote_retrieve_header()](https://developer.wordpress.org/reference/functions/wp_remote_retrieve_header/)`wp-includes/http.php` |

Retrieves a single header by name from the raw response.

  | 
| [wp_safe_remote_get()](https://developer.wordpress.org/reference/functions/wp_safe_remote_get/)`wp-includes/http.php` |

Retrieves the raw response from a safe HTTP request using the GET method.

  | 
| [wp_remote_retrieve_body()](https://developer.wordpress.org/reference/functions/wp_remote_retrieve_body/)`wp-includes/http.php` |

Retrieves only the body from the raw response.

  | 
| [_deprecated_argument()](https://developer.wordpress.org/reference/functions/_deprecated_argument/)`wp-includes/functions.php` |

Marks a function argument as deprecated and inform when it has been used.

  | 
| [is_wp_error()](https://developer.wordpress.org/reference/functions/is_wp_error/)`wp-includes/load.php` |

Checks whether the given variable is a WordPress Error.

  |

[Show 2 more](https://developer.wordpress.org/reference/functions/discover_pingback_server_uri/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/discover_pingback_server_uri/?output_format=md#)

| Used by | Description | 
| [pingback()](https://developer.wordpress.org/reference/functions/pingback/)`wp-includes/comment.php` |

Pings back the links found in a post.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/discover_pingback_server_uri/?output_format=md#changelog)󠁿

| Version | Description | 
| [1.5.0](https://developer.wordpress.org/reference/since/1.5.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fdiscover_pingback_server_uri%2F)
before being able to contribute a note or feedback.