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

---

# WP_REST_Sidebars_Controller::prepare_links( array $sidebar ): array

## In this article

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

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

Prepares links for the sidebar.

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

 `$sidebar`arrayrequired

Sidebar.

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

 array Links for the given widget.

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

    ```php
    protected function prepare_links( $sidebar ) {
    	return array(
    		'collection'               => array(
    			'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ),
    		),
    		'self'                     => array(
    			'href' => rest_url( sprintf( '%s/%s/%s', $this->namespace, $this->rest_base, $sidebar['id'] ) ),
    		),
    		'https://api.w.org/widget' => array(
    			'href'       => add_query_arg( 'sidebar', $sidebar['id'], rest_url( '/wp/v2/widgets' ) ),
    			'embeddable' => true,
    		),
    	);
    }
    ```

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

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_rest_sidebars_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.

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

Retrieves a modified URL query string.

  |

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

Prepares a single sidebar output for response.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_rest_sidebars_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_sidebars_controller%2Fprepare_links%2F)
before being able to contribute a note or feedback.