get_theme_mod() - WordPress 函数参考中文文档

返回介绍

get_theme_mod()

发布于 2017-09-11 字数4894 浏览 963 评论 0

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

Retrieve theme modification value for the current theme.


描述

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 );
}

更新日志

Version 描述
2.1.0 Introduced.

相关函数

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

上一篇:get_theme_file_uri()

下一篇:get_theme_mods()

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!