WP_REST_Response::add_link() public WP 4.4.0
Adds a link to the response.
{} It's a method of the class: WP_REST_Response{}
No Hooks.
Return
Null. Nothing.
Usage
$WP_REST_Response = new WP_REST_Response(); $WP_REST_Response->add_link( $rel, $href, $attributes );
- $rel(string) (required)
- Link relation. Either an IANA registered type, or an absolute URL.
- $href(string) (required)
- Target URI for the link.
- $attributes(array)
- Link parameters to send along with the URL.
Default: empty array
Changelog
Since 4.4.0 | Introduced. |
Code of WP_REST_Response::add_link() WP REST Response::add link WP 5.6
public function add_link( $rel, $href, $attributes = array() ) {
if ( empty( $this->links[ $rel ] ) ) {
$this->links[ $rel ] = array();
}
if ( isset( $attributes['href'] ) ) {
// Remove the href attribute, as it's used for the main URL.
unset( $attributes['href'] );
}
$this->links[ $rel ][] = array(
'href' => $href,
'attributes' => $attributes,
);
}