WP_REST_Response::add_link()
Adds a link to the response.
Method of the class: WP_REST_Response{}
No Hooks.
Return
null
. Nothing (null).
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. |
WP_REST_Response::add_link() WP REST Response::add link code WP 6.6.2
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, ); }