функция since 2.1.0

get_theme_mod()

Проверено на WordPress 6.9, обновлено Источник: WordPress Developer Resources.

Сигнатура

get_theme_mod( string $name, mixed $default_value = false ): mixed

Описание

Если имя модификации не существует, а $default_value является строкой, значение по умолчанию будет пропущено через PHP-функцию sprintf() с URI каталога шаблона в качестве первого значения и URI каталога таблицы стилей в качестве второго.

Оригинал (английский)

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

Параметры

$name string обязательный
Имя модификации темы.
$default_value mixed необязательный = false
Значение модификации темы по умолчанию.

Возвращаемое значение

mixed

Исходный код

wp-includes/theme.php:1064

function get_theme_mod( $name, $default_value = 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 mixed $current_mod The value of the active theme modification.
		 */
		return apply_filters( "theme_mod_{$name}", $mods[ $name ] );
	}

	if ( is_string( $default_value ) ) {
		// Only run the replacement if an sprintf() string format pattern was found.
		if ( preg_match( '#(?<!%)%(?:\d+\$?)?s#', $default_value ) ) {
			// Remove a single trailing percent sign.
			$default_value = preg_replace( '#(?<!%)%$#', '', $default_value );
			$default_value = sprintf( $default_value, get_template_directory_uri(), get_stylesheet_directory_uri() );
		}
	}

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

История изменений

ВерсияОписание
2.1.0 Introduced.

Что будем искать? Например,Продвижение

Этот сайт использует куки-файлы. Оставаясь на сайте, Вы соглашаетесь на их использование. Для получения дополнительной информации, пожалуйста, ознакомьтесь с политикой в отношении персональных данных.