WP_REST_Response::link_header() WordPress Method

The WP_REST_Response::link_header() method is used to add a link header to a WP_REST_Response object. This is typically used to add pagination links to a response.

WP_REST_Response::link_header( string $rel, string $link, array $other = array() ) #

Sets a single link header.


Parameters

$rel

(string)(Required)Link relation. Either an IANA registered type, or an absolute URL.

$link

(string)(Required)Target IRI for the link.

$other

(array)(Optional) Other parameters to send, as an associative array.

Default value: array()


Top ↑

Source

File: wp-includes/rest-api/class-wp-rest-response.php

	public function link_header( $rel, $link, $other = array() ) {
		$header = '<' . $link . '>; rel="' . $rel . '"';

		foreach ( $other as $key => $value ) {
			if ( 'title' === $key ) {
				$value = '"' . $value . '"';
			}

			$header .= '; ' . $key . '=' . $value;
		}
		$this->header( 'Link', $header, false );
	}

Top ↑

Changelog

Changelog
VersionDescription
4.4.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.