WP_Theme_JSON::get_template_parts() WordPress Method

The WP_Theme_JSON::get_template_parts() method is used to retrieve an array of template parts for a given theme. This is useful for creating a list of all the template files that are required for a theme to function properly.

WP_Theme_JSON::get_template_parts() #

Returns the template part data of active theme.


Return

(array)


Top ↑

Source

File: wp-includes/class-wp-theme-json.php

	public function get_template_parts() {
		$template_parts = array();
		if ( ! isset( $this->theme_json['templateParts'] ) || ! is_array( $this->theme_json['templateParts'] ) ) {
			return $template_parts;
		}

		foreach ( $this->theme_json['templateParts'] as $item ) {
			if ( isset( $item['name'] ) ) {
				$template_parts[ $item['name'] ] = array(
					'title' => isset( $item['title'] ) ? $item['title'] : '',
					'area'  => isset( $item['area'] ) ? $item['area'] : '',
				);
			}
		}
		return $template_parts;
	}

Top ↑

Changelog

Changelog
VersionDescription
5.9.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.