W3cubDocs

/WordPress

get_block_theme_folders( string $theme_stylesheet = null ): string[]

For backward compatibility reasons, block themes might be using block-templates or block-template-parts, this function ensures we fallback to these folders properly.

Parameters

$theme_stylesheetstringoptional
The stylesheet. Default is to leverage the main theme root.

Default:null

Return

string[] Folder names used by block themes.
  • wp_template string
    Theme-relative directory name for block templates.
  • wp_template_part string
    Theme-relative directory name for block template parts.

Source

function get_block_theme_folders( $theme_stylesheet = null ) {
	$theme = wp_get_theme( (string) $theme_stylesheet );
	if ( ! $theme->exists() ) {
		// Return the default folders if the theme doesn't exist.
		return array(
			'wp_template'      => 'templates',
			'wp_template_part' => 'parts',
		);
	}
	return $theme->get_block_template_folders();
}

Changelog

Version Description
5.9.0 Introduced.

© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/get_block_theme_folders