返回介绍

get_theme_mod()

发布于 2017-09-11 00:24:45 字数 4892 浏览 1401 评论 0 收藏 0

get_theme_mod( string $name,  bool|string $default = false )

Retrieve theme modification value for the current theme.


description

If the modification name does not exist, then the $default will be passed through sprintf() PHP function with the first string the template directory URI and the second string the stylesheet directory URI.


参数

$name

(string) (Required) Theme modification name.

$default

(bool|string) (Optional)

Default value: false


返回值

(string)


源代码

File: wp-includes/theme.php

function get_theme_mod( $name, $default = false ) {
	$mods = get_theme_mods();

	if ( isset( $mods[$name] ) ) {
		/**
		 * Filters the theme modification, or 'theme_mod', value.
		 *
		 * The dynamic portion of the hook name, `$name`, refers to
		 * the key name of the modification array. For example,
		 * 'header_textcolor', 'header_image', and so on depending
		 * on the theme options.
		 *
		 * @since 2.2.0
		 *
		 * @param string $current_mod The value of the current theme modification.
		 */
		return apply_filters( "theme_mod_{$name}", $mods[$name] );
	}

	if ( is_string( $default ) )
		$default = sprintf( $default, get_template_directory_uri(), get_stylesheet_directory_uri() );

	/** This filter is documented in wp-includes/theme.php */
	return apply_filters( "theme_mod_{$name}", $default );
}

更新日志

Versiondescription
2.1.0Introduced.

相关函数

Uses

  • wp-includes/theme.php: theme_mod_{$name}
  • wp-includes/theme.php: get_theme_mods()
  • wp-includes/theme.php: get_template_directory_uri()
  • wp-includes/theme.php: get_stylesheet_directory_uri()
  • wp-includes/plugin.php: apply_filters()

Used By

  • wp-includes/theme.php: wp_get_custom_css_post()
  • wp-includes/theme.php: get_header_video_url()
  • wp-includes/theme.php: _custom_logo_header_styles()
  • wp-includes/general-template.php: has_custom_logo()
  • wp-includes/general-template.php: get_custom_logo()
  • wp-includes/class-wp-customize-setting.php: WP_Customize_Setting::get_root_value()
  • wp-admin/includes/template.php: _media_states()
  • wp-admin/custom-header.php: Custom_Image_Header::show_header_selector()
  • wp-admin/custom-background.php: Custom_Background::admin_page()
  • wp-includes/theme.php: get_background_color()
  • wp-includes/theme.php: _custom_background_cb()
  • wp-includes/theme.php: _delete_attachment_theme_mod()
  • wp-includes/theme.php: get_header_textcolor()
  • wp-includes/theme.php: display_header_text()
  • wp-includes/theme.php: get_header_image()
  • wp-includes/theme.php: _get_random_header_data()
  • wp-includes/theme.php: is_random_header_image()
  • wp-includes/theme.php: get_custom_header()
  • wp-includes/theme.php: get_background_image()
  • wp-includes/theme.php: switch_theme()
  • wp-includes/nav-menu.php: get_nav_menu_locations()
  • wp-includes/widgets.php: retrieve_widgets()
  • Show 17 more used by Hide more used by

User Contributed Notes

  1. Skip to note content You must log in to vote on the helpfulness of this noteVote results for this note: 1You must log in to vote on the helpfulness of this note Contributed by Codex

    Calling the custom background color
    This example could be used to add the custom background color as a border on the top of the footer. It would be css inserted in the header:

    
    .footer {
         border-top: solid 1px
  2. Calling Background color with a default value
    Sometimes you need to set default value for avoid any bad situation. This example could be used to add the custom background color as a border on the top of the footer with default color white. It would be css inserted in the header:

    .footer {
         border-top: solid 1px

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文