WP_REST_Response::add_link( string $rel, string $href, array $attributes = array() )

In this article

Adds a link to the response.

Parameters

$relstringrequired
Link relation. Either an IANA registered type, or an absolute URL.
$hrefstringrequired
Target URI for the link.
$attributesarrayoptional
Link parameters to send along with the URL.

Default:array()

Source

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,
	);
}

Changelog

VersionDescription
4.4.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.