Title: WP_Theme::cache_add
Published: April 25, 2014
Last modified: August 20, 2026

---

# WP_Theme::cache_add( string $key, array|string $data ): bool

## In this article

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

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

This function’s access is marked private. This means it is not intended for use 
by plugin or theme developers, only by core. It is listed here for completeness.

Adds theme data to cache.

## 󠀁[Description](https://developer.wordpress.org/reference/classes/wp_theme/cache_add/?output_format=md#description)󠁿

Cache entries keyed by the theme and the type of data.

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

 `$key`stringrequired

Type of data to store (theme, screenshot, headers, post_templates)

`$data`array|stringrequired

Data to store

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

 bool Return value from [wp_cache_add()](https://developer.wordpress.org/reference/functions/wp_cache_add/)

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

    ```php
    private function cache_add( $key, $data ) {
    	return wp_cache_add( $key . '-' . $this->cache_hash, $data, 'themes', self::$cache_expiration );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/class-wp-theme.php#L813)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/class-wp-theme.php#L813-L815)

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

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

Adds data to the cache, if the cache key doesn’t already exist.

  |

| Used by | Description | 
| [WP_Theme::get_post_templates()](https://developer.wordpress.org/reference/classes/wp_theme/get_post_templates/)`wp-includes/class-wp-theme.php` |

Returns the theme’s post templates.

  | 
| [WP_Theme::get_screenshot()](https://developer.wordpress.org/reference/classes/wp_theme/get_screenshot/)`wp-includes/class-wp-theme.php` |

Returns the main screenshot file for the theme.

  | 
| [WP_Theme::get()](https://developer.wordpress.org/reference/classes/wp_theme/get/)`wp-includes/class-wp-theme.php` |

Gets a raw, unformatted theme header.

  | 
| [WP_Theme::__construct()](https://developer.wordpress.org/reference/classes/wp_theme/__construct/)`wp-includes/class-wp-theme.php` |

Constructor for [WP_Theme](https://developer.wordpress.org/reference/classes/wp_theme/).

  |

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

| Version | Description | 
| [3.4.0](https://developer.wordpress.org/reference/since/3.4.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_theme%2Fcache_add%2F)
before being able to contribute a note or feedback.