Title: WP_REST_Server::get_target_hints_for_link
Published: November 13, 2024
Last modified: May 20, 2026

---

# WP_REST_Server::get_target_hints_for_link( array $link ): array|null

## In this article

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

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

Gets the target hints for a REST API Link.

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

 `$link`arrayrequired

The link to get target hints for.

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

 array|null

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

    ```php
    protected static function get_target_hints_for_link( $link ) {
    	// Prefer targetHints that were specifically designated by the developer.
    	if ( isset( $link['targetHints']['allow'] ) ) {
    		return null;
    	}

    	$request = WP_REST_Request::from_url( $link['href'] );
    	if ( ! $request ) {
    		return null;
    	}

    	$server = rest_get_server();
    	$match  = $server->match_request_to_handler( $request );

    	if ( is_wp_error( $match ) ) {
    		return null;
    	}

    	if ( is_wp_error( $request->has_valid_params() ) ) {
    		return null;
    	}

    	if ( is_wp_error( $request->sanitize_params() ) ) {
    		return null;
    	}

    	$target_hints = array();

    	$response = new WP_REST_Response();
    	$response->set_matched_route( $match[0] );
    	$response->set_matched_handler( $match[1] );
    	$headers = rest_send_allow_header( $response, $server, $request )->get_headers();

    	foreach ( $headers as $name => $value ) {
    		$name = WP_REST_Request::canonicalize_header_name( $name );

    		$target_hints[ $name ] = array_map( 'trim', explode( ',', $value ) );
    	}

    	return $target_hints;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/class-wp-rest-server.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/rest-api/class-wp-rest-server.php#L660)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/rest-api/class-wp-rest-server.php#L660-L700)

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

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

Retrieves the current REST server instance.

  | 
| [WP_REST_Request::from_url()](https://developer.wordpress.org/reference/classes/wp_rest_request/from_url/)`wp-includes/rest-api/class-wp-rest-request.php` |

Retrieves a [WP_REST_Request](https://developer.wordpress.org/reference/classes/wp_rest_request/) object from a full URL.

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

Sends the “Allow” header to state all methods that can be sent to the current route.

  | 
| [WP_REST_Request::canonicalize_header_name()](https://developer.wordpress.org/reference/classes/wp_rest_request/canonicalize_header_name/)`wp-includes/rest-api/class-wp-rest-request.php` |

Canonicalizes the header name.

  | 
| [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 1 more](https://developer.wordpress.org/reference/classes/wp_rest_server/get_target_hints_for_link/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/classes/wp_rest_server/get_target_hints_for_link/?output_format=md#)

| Used by | Description | 
| [WP_REST_Server::get_response_links()](https://developer.wordpress.org/reference/classes/wp_rest_server/get_response_links/)`wp-includes/rest-api/class-wp-rest-server.php` |

Retrieves links from a response.

  |

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

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

## User Contributed Notes

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