WP_REST_Response::add_links() WordPress Method

The add_links() method is used to add links to the WP_REST_Response object. This is useful for linking to related resources, such as the author of a post.

WP_REST_Response::add_links( array $links ) #

Adds multiple links to the response.


Description

Link data should be an associative array with link relation as the key. The value can either be an associative array of link attributes (including href with the URL for the response), or a list of these associative arrays.


Top ↑

Parameters

$links

(array)(Required)Map of link relation to list of links.


Top ↑

Source

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

	public function add_links( $links ) {
		foreach ( $links as $rel => $set ) {
			// If it's a single link, wrap with an array for consistent handling.
			if ( isset( $set['href'] ) ) {
				$set = array( $set );
			}

			foreach ( $set as $attributes ) {
				$this->add_link( $rel, $attributes['href'], $attributes );
			}
		}
	}


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.