get_theme_data

函数
get_theme_data ( $theme_file )
参数
  • (string) $theme_file Theme file path.
    Required:
返回值
  • (array) Theme data.
相关
  • wp_get_theme()
定义位置
相关方法
get_the_dateget_theme_updatesget_theme_modget_theme_modsget_theme_root
引入
1.5.0
弃用
3.4.0

get_theme_data: 这个函数返回一个关于主题的元数据数组,如主题名称、版本、作者、描述等等。它需要该主题的style.css文件的完整路径。

从解析的主题文件中获取主题数据。

function get_theme_data( $theme_file ) {
	_deprecated_function( __FUNCTION__, '3.4.0', 'wp_get_theme()' );
	$theme = new WP_Theme( wp_basename( dirname( $theme_file ) ), dirname( dirname( $theme_file ) ) );

	$theme_data = array(
		'Name' => $theme->get('Name'),
		'URI' => $theme->display('ThemeURI', true, false),
		'Description' => $theme->display('Description', true, false),
		'Author' => $theme->display('Author', true, false),
		'AuthorURI' => $theme->display('AuthorURI', true, false),
		'Version' => $theme->get('Version'),
		'Template' => $theme->get('Template'),
		'Status' => $theme->get('Status'),
		'Tags' => $theme->get('Tags'),
		'Title' => $theme->get('Name'),
		'AuthorName' => $theme->get('Author'),
	);

	foreach ( apply_filters( 'extra_theme_headers', array() ) as $extra_header ) {
		if ( ! isset( $theme_data[ $extra_header ] ) )
			$theme_data[ $extra_header ] = $theme->get( $extra_header );
	}

	return $theme_data;
}

常见问题

FAQs
查看更多 >