Title: WP_REST_Response::add_link
Published: December 9, 2015
Last modified: August 20, 2026

---

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

## In this article

 * [Description](https://developer.wordpress.org/reference/classes/wp_rest_response/add_link/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/classes/wp_rest_response/add_link/?output_format=md#parameters)
 * [Source](https://developer.wordpress.org/reference/classes/wp_rest_response/add_link/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wp_rest_response/add_link/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_rest_response/add_link/?output_format=md#changelog)

Adds a link to the response.

## 󠀁[Description](https://developer.wordpress.org/reference/classes/wp_rest_response/add_link/?output_format=md#description)󠁿

{@internal The $rel parameter is first, as this looks nicer when sending multiple.}

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/wp_rest_response/add_link/?output_format=md#parameters)󠁿

 `$rel`stringrequired

Link relation. Either an IANA registered type, or an absolute URL.

`$href`stringrequired

Target URI for the link.

`$attributes`arrayoptional

Link parameters to send along with the URL.

Default:`array()`

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_rest_response/add_link/?output_format=md#source)󠁿

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

[View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/class-wp-rest-response.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/rest-api/class-wp-rest-response.php#L58)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/rest-api/class-wp-rest-response.php#L58-L72)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_rest_response/add_link/?output_format=md#related)󠁿

| Used by | Description | 
| [WP_REST_Response::add_links()](https://developer.wordpress.org/reference/classes/wp_rest_response/add_links/)`wp-includes/rest-api/class-wp-rest-response.php` |

Adds multiple links to the response.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_rest_response/add_link/?output_format=md#changelog)󠁿

| Version | Description | 
| [4.4.0](https://developer.wordpress.org/reference/since/4.4.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_rest_response%2Fadd_link%2F)
before being able to contribute a note or feedback.