Title: WP_REST_Widgets_Controller::prepare_links
Published: July 20, 2021
Last modified: February 24, 2026

---

# WP_REST_Widgets_Controller::prepare_links( array $prepared ): array

## In this article

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

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

Prepares links for the widget.

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

 `$prepared`arrayrequired

Widget.

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

 array Links for the given widget.

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

    ```php
    protected function prepare_links( $prepared ) {
    	$id_base = ! empty( $prepared['id_base'] ) ? $prepared['id_base'] : $prepared['id'];

    	return array(
    		'self'                      => array(
    			'href' => rest_url( sprintf( '%s/%s/%s', $this->namespace, $this->rest_base, $prepared['id'] ) ),
    		),
    		'collection'                => array(
    			'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ),
    		),
    		'about'                     => array(
    			'href'       => rest_url( sprintf( 'wp/v2/widget-types/%s', $id_base ) ),
    			'embeddable' => true,
    		),
    		'https://api.w.org/sidebar' => array(
    			'href' => rest_url( sprintf( 'wp/v2/sidebars/%s/', $prepared['sidebar'] ) ),
    		),
    	);
    }
    ```

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

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

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

Retrieves the URL to a REST endpoint.

  |

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

Prepares the widget for the REST response.

  |

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

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