Title: rest_get_queried_resource_route
Published: August 11, 2020
Last modified: August 20, 2026

---

# rest_get_queried_resource_route(): string

## In this article

 * [Return](https://developer.wordpress.org/reference/functions/rest_get_queried_resource_route/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/rest_get_queried_resource_route/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/rest_get_queried_resource_route/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/rest_get_queried_resource_route/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/rest_get_queried_resource_route/?output_format=md#changelog)

Gets the REST route for the currently queried object.

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

 string The REST route of the resource, or an empty string if no resource identified.

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

    ```php
    function rest_get_queried_resource_route() {
    	if ( is_singular() ) {
    		$route = rest_get_route_for_post( get_queried_object() );
    	} elseif ( is_category() || is_tag() || is_tax() ) {
    		$route = rest_get_route_for_term( get_queried_object() );
    	} elseif ( is_author() ) {
    		$route = '/wp/v2/users/' . get_queried_object_id();
    	} else {
    		$route = '';
    	}

    	/**
    	 * Filters the REST route for the currently queried object.
    	 *
    	 * @since 5.5.0
    	 *
    	 * @param string $link The route with a leading slash, or an empty string.
    	 */
    	return apply_filters( 'rest_queried_resource_route', $route );
    }
    ```

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

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/rest_get_queried_resource_route/?output_format=md#hooks)󠁿

 [apply_filters( ‘rest_queried_resource_route’, string $link )](https://developer.wordpress.org/reference/hooks/rest_queried_resource_route/)

Filters the REST route for the currently queried object.

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

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

Gets the REST API route for a post.

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

Gets the REST API route for a term.

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

Determines whether the query is for an existing single post of any post type (post, attachment, page, custom post types).

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

Determines whether the query is for an existing category archive page.

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

Determines whether the query is for an existing tag archive page.

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

Determines whether the query is for an existing custom taxonomy archive page.

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

Determines whether the query is for an existing author archive page.

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

Retrieves the currently queried object.

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

Retrieves the ID of the currently queried object.

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

Calls the callback functions that have been added to a filter hook.

  |

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

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

Outputs the REST API link tag into page header.

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

Sends a Link header for the REST API.

  |

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

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

## User Contributed Notes

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