get_theme_mods() WordPress Function

The get_theme_mods() function is used to retrieve all customizations made to a WordPress theme. This function can be used to retrieve theme mod values for a specific theme or for the current theme.

get_theme_mods() #

Retrieves all theme modifications.


Return

(array) Theme modifications.


Top ↑

More Information

This function will update the options for theme mods which were created in older WordPress versions that used the deprecated mods_$theme_name option key to now use theme_mod_$name.


Top ↑

Source

File: wp-includes/theme.php

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


Top ↑

Changelog

Changelog
VersionDescription
5.9.0The return value is always an array.
3.1.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More