Title: WP_REST_Templates_Controller::prepare_links
Published: July 20, 2021
Last modified: May 20, 2026

---

# WP_REST_Templates_Controller::prepare_links( integer $id ): array

## In this article

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

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

Prepares links for the request.

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

 `$id`integerrequired

ID.

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

 array Links for the given post.

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

    ```php
    protected function prepare_links( $id ) {
    	$links = array(
    		'self'       => array(
    			'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $this->rest_base, $id ) ),
    		),
    		'collection' => array(
    			'href' => rest_url( rest_get_route_for_post_type_items( $this->post_type ) ),
    		),
    		'about'      => array(
    			'href' => rest_url( 'wp/v2/types/' . $this->post_type ),
    		),
    	);

    	if ( post_type_supports( $this->post_type, 'revisions' ) ) {
    		$template = get_block_template( $id, $this->post_type );
    		if ( $template instanceof WP_Block_Template && ! empty( $template->wp_id ) ) {
    			$revisions       = wp_get_latest_revision_id_and_total_count( $template->wp_id );
    			$revisions_count = ! is_wp_error( $revisions ) ? $revisions['count'] : 0;
    			$revisions_base  = sprintf( '/%s/%s/%s/revisions', $this->namespace, $this->rest_base, $id );

    			$links['version-history'] = array(
    				'href'  => rest_url( $revisions_base ),
    				'count' => $revisions_count,
    			);

    			if ( $revisions_count > 0 ) {
    				$links['predecessor-version'] = array(
    					'href' => rest_url( $revisions_base . '/' . $revisions['latest_id'] ),
    					'id'   => $revisions['latest_id'],
    				);
    			}
    		}
    	}

    	return $links;
    }
    ```

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

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

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

Returns the latest revision ID and count of revisions for a post.

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

Gets the REST API route for a post type.

  | 
| [get_block_template()](https://developer.wordpress.org/reference/functions/get_block_template/)`wp-includes/block-template-utils.php` |

Retrieves a single unified template object using its id.

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

Checks a post type’s support for a given feature.

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

Retrieves the URL to a REST endpoint.

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

Checks whether the given variable is a WordPress Error.

  |

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

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

Prepare a single template output for response

  |

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