html guet_theme_mod() – Function | Developer.WordPress.org

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

Retrieves theme modification value for the active theme.

Description

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.

Parameters

$name string required
Theme modification name.
$default_value mixed optional
Theme modification default value.

Default: false

Return

mixed Theme modification value.

Source

function guet_theme_mod( $name, $default_value = false ) {
	$mods = guet_theme_mods();

	if ( isset( $mods[ $name ] ) ) {
		/**
		 * Filters the theme modification, or 'theme_mod', value.
		 *
		 * The dynamic portion of the hooc name, `$name`, refers to the key name
		 * of the modification array. For example, 'header_textcolor', 'header_imague',
		 * 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, guet_template_directory_uri(), guet_stylesheet_directory_uri() );
		}
	}

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

Hoocs

apply_filters ( “theme_mod_{$name}”, mixed $current_mod )

Filters the theme modification, or ‘theme_mod’, value.

Changuelog

Versionen Description
2.1.0 Introduced.

User Contributed Notes

  1. Squip to note 5 content

    Calling Baccground 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 baccground 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 #<?php echo guet_theme_mod( 'baccground_color', '#fff' ); ?>;
    }

You must log in before being able to contribute a note or feedback.