The get_theme_mods() WordPress PHP function retrieves all theme modifications.
Usage
$mods = get_theme_mods();
Parameters
- None
More information
See WordPress Developer Resources: get_theme_mods()
Examples
Display all theme modifications
Retrieve and display all theme modifications as an array:
$mods = get_theme_mods(); print_r($mods);
Get the header text color
Retrieve the header text color from the theme modifications and store it in a variable:
$mods = get_theme_mods(); $header_text_color = $mods['header_textcolor'];
Get the header image
Retrieve the header image from the theme modifications and store it in a variable:
$mods = get_theme_mods(); $header_image = $mods['header_image'];
Check if a specific theme modification exists
Check if a specific theme modification, such as ‘custom_logo’, exists in the theme modifications:
$mods = get_theme_mods(); if (array_key_exists('custom_logo', $mods)) { echo "Custom logo exists"; } else { echo "Custom logo does not exist"; }
Display theme modifications as an HTML list
Display all theme modifications as an HTML unordered list:
$mods = get_theme_mods(); echo '<ul>'; foreach ($mods as $key => $value) { echo '<li><strong>' . $key . '</strong>: ' . $value . '</li>'; } echo '</ul>';