remove_theme_mod()
Deletes the specified setting (option) of the current theme, set using set_theme_mod().
If there are no options left in the theme options array after deleting the option, the theme options will be completely removed from the wp_options table, i.e., the function remove_theme_mods() will be used.
1 time — 0.001562 sec (very slow) | 50000 times — 2.79 sec (fast)
No Hooks.
Returns
null. Returns nothing.
Usage
remove_theme_mod( $name );
- $name(string) (required)
- The name of the theme option.
Examples
#1 Deleting special options
// let's say we added an option like this set_theme_mod( 'my_theme_option', 123 ); //and here we need to remove the option. Delete: remove_theme_mod( 'my_theme_option' );
Changelog
| Since 2.1.0 | Introduced. |
remove_theme_mod() remove theme mod code WP 6.9.1
function remove_theme_mod( $name ) {
$mods = get_theme_mods();
if ( ! isset( $mods[ $name ] ) ) {
return;
}
unset( $mods[ $name ] );
if ( empty( $mods ) ) {
remove_theme_mods();
return;
}
$theme = get_option( 'stylesheet' );
update_option( "theme_mods_$theme", $mods );
}