Title: WP_REST_Server::add_active_theme_link_to_index
Published: March 9, 2021
Last modified: May 20, 2026

---

# WP_REST_Server::add_active_theme_link_to_index( WP_REST_Response $response )

## In this article

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

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

Adds a link to the active theme for users who have proper permissions.

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

 `$response`[WP_REST_Response](https://developer.wordpress.org/reference/classes/wp_rest_response/)
required

REST API response.

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

    ```php
    protected function add_active_theme_link_to_index( WP_REST_Response $response ) {
    	$should_add = current_user_can( 'switch_themes' ) || current_user_can( 'manage_network_themes' );

    	if ( ! $should_add && current_user_can( 'edit_posts' ) ) {
    		$should_add = true;
    	}

    	if ( ! $should_add ) {
    		foreach ( get_post_types( array( 'show_in_rest' => true ), 'objects' ) as $post_type ) {
    			if ( current_user_can( $post_type->cap->edit_posts ) ) {
    				$should_add = true;
    				break;
    			}
    		}
    	}

    	if ( $should_add ) {
    		$theme = wp_get_theme();
    		$response->add_link( 'https://api.w.org/active-theme', rest_url( 'wp/v2/themes/' . $theme->get_stylesheet() ) );
    	}
    }
    ```

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

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

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

Returns whether the current user has the specified capability.

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

Gets a [WP_Theme](https://developer.wordpress.org/reference/classes/wp_theme/) object for a theme.

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

Gets a list of all registered post type objects.

  |

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

| Used by | Description | 
| [WP_REST_Server::get_index()](https://developer.wordpress.org/reference/classes/wp_rest_server/get_index/)`wp-includes/rest-api/class-wp-rest-server.php` |

Retrieves the site index.

  |

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

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