函数文档

get_stylesheet()

💡 云策文档标注

概述

get_stylesheet() 函数用于获取当前前端主题的名称,通常与模板名称相同。它返回一个字符串,表示当前样式表的名称。

关键要点

  • 函数返回当前激活主题的样式表名称,通常与模板名称一致。
  • 内部通过 get_option('stylesheet') 获取值,并应用 'stylesheet' 过滤器进行修改。
  • 在 WordPress 1.5.0 版本中引入,常用于主题和模板相关操作。

代码示例

function get_stylesheet() {
	return apply_filters( 'stylesheet', get_option( 'stylesheet' ) );
}

注意事项

  • 此函数主要用于前端主题,不适用于管理界面主题。
  • 返回值是字符串,可直接用于路径或标识符构建。

📄 原文内容

Retrieves name of the current stylesheet.

Description

The theme name that is currently set as the front end theme.

For all intents and purposes, the template name and the stylesheet name are going to be the same for most cases.

Return

string Stylesheet name.

Source

function get_stylesheet() {
	/**
	 * Filters the name of current stylesheet.
	 *
	 * @since 1.5.0
	 *
	 * @param string $stylesheet Name of the current stylesheet.
	 */
	return apply_filters( 'stylesheet', get_option( 'stylesheet' ) );
}

Hooks

apply_filters( ‘stylesheet’, string $stylesheet )

Filters the name of current stylesheet.

Changelog

Version Description
1.5.0 Introduced.