On this page
get_theme_mod( string $name, mixed $default = false ): mixed
Retrieves theme modification value for the active theme.
Description
If the modification name does not exist and $default 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
$namestring Required-
Theme modification name.
$defaultmixed Optional-
Theme modification default value.
Default:
false
Return
mixed Theme modification value.
Source
File: wp-includes/theme.php. View all references
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 mixed $current_mod The value of the active theme modification.
*/
return apply_filters( "theme_mod_{$name}", $mods[ $name ] );
}
if ( is_string( $default ) ) {
// Only run the replacement if an sprintf() string format pattern was found.
if ( preg_match( '#(?<!%)%(?:\d+\$?)?s#', $default ) ) {
// Remove a single trailing percent sign.
$default = preg_replace( '#(?<!%)%$#', '', $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 );
}
Hooks
- apply_filters( "theme_mod_{$name}",
mixed $current_mod ) -
Filters the theme modification, or ‘theme_mod’, value.
Related
Uses
| Uses | Description |
|---|---|
| get_theme_mods() wp-includes/theme.php | Retrieves all theme modifications. |
| get_template_directory_uri() wp-includes/theme.php | Retrieves template directory URI for the active theme. |
| get_stylesheet_directory_uri() wp-includes/theme.php | Retrieves stylesheet directory URI for the active theme. |
| apply_filters() wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. |
Used By
| Used By | Description |
|---|---|
| WP_REST_Server::add_site_logo_to_index() wp-includes/rest-api/class-wp-rest-server.php | Exposes the site logo through the WordPress REST API. |
| get_media_states() wp-admin/includes/template.php | Retrieves an array of media states from an attachment. |
| wp_map_sidebars_widgets() wp-includes/widgets.php | Compares a list of sidebars with their widgets against an allowed list. |
| wp_get_custom_css_post() wp-includes/theme.php | Fetches the |
| get_header_video_url() wp-includes/theme.php | Retrieves header video URL for custom header. |
| _custom_logo_header_styles() wp-includes/theme.php | Adds CSS to hide header text for custom logo, based on Customizer setting. |
| has_custom_logo() wp-includes/general-template.php | Determines whether the site has a custom logo. |
| get_custom_logo() wp-includes/general-template.php | Returns a custom logo, linked to home unless the theme supports removing the link on the home page. |
| WP_Customize_Setting::get_root_value() wp-includes/class-wp-customize-setting.php | Get the root value for a setting, especially for multidimensional ones. |
| Custom_Image_Header::show_header_selector() wp-admin/includes/class-custom-image-header.php | Display UI for selecting one of several default headers. |
| Custom_Background::admin_page() wp-admin/includes/class-custom-background.php | Displays the custom background page. |
| get_background_color() wp-includes/theme.php | Retrieves value for custom background color. |
| _custom_background_cb() wp-includes/theme.php | Default custom background callback. |
| _delete_attachment_theme_mod() wp-includes/theme.php | Checks an attachment being deleted to see if it’s a header or background image. |
| get_header_textcolor() wp-includes/theme.php | Retrieves the custom header text color in 3- or 6-digit hexadecimal form. |
| display_header_text() wp-includes/theme.php | Whether to display the header text. |
| get_header_image() wp-includes/theme.php | Retrieves header image for custom header. |
| _get_random_header_data() wp-includes/theme.php | Gets random header image data from registered images in theme. |
| is_random_header_image() wp-includes/theme.php | Checks if random header image is in use. |
| get_custom_header() wp-includes/theme.php | Gets the header image data. |
| get_background_image() wp-includes/theme.php | Retrieves background image for custom background. |
| switch_theme() wp-includes/theme.php | Switches the theme. |
| get_nav_menu_locations() wp-includes/nav-menu.php | Retrieves all registered navigation menu locations and the menus assigned to them. |
| retrieve_widgets() wp-includes/widgets.php | Validates and remaps any “orphaned” widgets to wp_inactive_widgets sidebar, and saves the widget settings. This has to run at least on each theme change. |
Changelog
| Version | Description |
|---|---|
| 2.1.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/get_theme_mod