Title: WP_REST_Menus_Controller::prepare_links
Published: February 3, 2022
Last modified: May 20, 2026

---

# WP_REST_Menus_Controller::prepare_links( WP_Term $term ): array

## In this article

 * [Parameters](https://developer.wordpress.org/reference/classes/wp_rest_menus_controller/prepare_links/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/classes/wp_rest_menus_controller/prepare_links/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wp_rest_menus_controller/prepare_links/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wp_rest_menus_controller/prepare_links/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_rest_menus_controller/prepare_links/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wp_rest_menus_controller/prepare_links/?output_format=md#wp--skip-link--target)

Prepares links for the request.

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

 `$term`[WP_Term](https://developer.wordpress.org/reference/classes/wp_term/)required

Term object.

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wp_rest_menus_controller/prepare_links/?output_format=md#return)󠁿

 array Links for the given term.

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

    ```php
    protected function prepare_links( $term ) {
    	$links = parent::prepare_links( $term );

    	$locations = $this->get_menu_locations( $term->term_id );
    	foreach ( $locations as $location ) {
    		$url = rest_url( sprintf( 'wp/v2/menu-locations/%s', $location ) );

    		$links['https://api.w.org/menu-location'][] = array(
    			'href'       => $url,
    			'embeddable' => true,
    		);
    	}

    	return $links;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-menus-controller.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/rest-api/endpoints/class-wp-rest-menus-controller.php#L160)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/rest-api/endpoints/class-wp-rest-menus-controller.php#L160-L174)

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

| Uses | Description | 
| [WP_REST_Menus_Controller::get_menu_locations()](https://developer.wordpress.org/reference/classes/wp_rest_menus_controller/get_menu_locations/)`wp-includes/rest-api/endpoints/class-wp-rest-menus-controller.php` |

Returns the names of the locations assigned to the menu.

  | 
| [WP_REST_Terms_Controller::prepare_links()](https://developer.wordpress.org/reference/classes/wp_rest_terms_controller/prepare_links/)`wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php` |

Prepares links for the request.

  | 
| [rest_url()](https://developer.wordpress.org/reference/functions/rest_url/)`wp-includes/rest-api.php` |

Retrieves the URL to a REST endpoint.

  |

[Show 1 more](https://developer.wordpress.org/reference/classes/wp_rest_menus_controller/prepare_links/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/classes/wp_rest_menus_controller/prepare_links/?output_format=md#)

| Used by | Description | 
| [WP_REST_Menus_Controller::prepare_item_for_response()](https://developer.wordpress.org/reference/classes/wp_rest_menus_controller/prepare_item_for_response/)`wp-includes/rest-api/endpoints/class-wp-rest-menus-controller.php` |

Prepares a single term output for response.

  |

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

| Version | Description | 
| [5.9.0](https://developer.wordpress.org/reference/since/5.9.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_menus_controller%2Fprepare_links%2F)
before being able to contribute a note or feedback.