get_theme_mods()WP 3.1.0

Retrieve all theme modifications.

1 time — 0.001737 sec (very slow) | 50000 times — 2.25 sec (fast) | PHP 7.0.32, WP 5.0.3

No Hooks.

Return

Array. Theme modifications.

Usage

get_theme_mods();

Examples

0

#1 Get all the settings

This example shows how to get all the theme mods (options) as an array.

$mods = get_theme_mods();

print_r( $mods );

/*
Array
(
	[0] =>
	[nav_menu_locations] => Array
			[header]        => 2
			[footer_credit] => 3
			[footer_left]   => 4
			[footer_right]  => 5

	[custom_css_post_id] => -1
	[custom_logo]        => 7
	[sidebars_widgets]   => Array
			[time] => 1550171673
			[data] => Array
					[wp_inactive_widgets] => Array
							[0] => search-2
							[1] => recent-posts-2
							[2] => recent-comments-2
							[3] => archives-2
							[4] => categories-2
							[5] => meta-2

	[footer_bg_image] => http://dh5.com/content/uploads/2019/02/bg-footer.jpg
)
*/

echo $mods['header_textcolor']; // > 333

Changelog

Since 3.1.0 Introduced.
Since 5.9.0 The return value is always an array.

get_theme_mods() code WP 6.7.2

function get_theme_mods() {
	$theme_slug = get_option( 'stylesheet' );
	$mods       = get_option( "theme_mods_$theme_slug" );

	if ( false === $mods ) {
		$theme_name = get_option( 'current_theme' );
		if ( false === $theme_name ) {
			$theme_name = wp_get_theme()->get( 'Name' );
		}

		$mods = get_option( "mods_$theme_name" ); // Deprecated location.
		if ( is_admin() && false !== $mods ) {
			update_option( "theme_mods_$theme_slug", $mods );
			delete_option( "mods_$theme_name" );
		}
	}

	if ( ! is_array( $mods ) ) {
		$mods = array();
	}

	return $mods;
}