函数文档

remove_theme_mods()

💡 云策文档标注

概述

remove_theme_mods() 函数用于删除当前活动主题的主题修改选项,包括新式和旧式存储方式。

关键要点

  • 删除主题修改选项:通过 delete_option() 移除 'theme_mods_' 加 stylesheet 的选项。
  • 兼容旧式存储:同时删除 'mods_' 加主题名称的旧选项,确保兼容性。
  • 依赖函数:使用 get_option()、wp_get_theme() 和 delete_option() 实现功能。

代码示例

function remove_theme_mods() {
    delete_option( 'theme_mods_' . get_option( 'stylesheet' ) );

    // Old style.
    $theme_name = get_option( 'current_theme' );
    if ( false === $theme_name ) {
        $theme_name = wp_get_theme()->get( 'Name' );
    }

    delete_option( 'mods_' . $theme_name );
}

📄 原文内容

Removes theme modifications option for the active theme.

Source

function remove_theme_mods() {
	delete_option( 'theme_mods_' . get_option( 'stylesheet' ) );

	// Old style.
	$theme_name = get_option( 'current_theme' );
	if ( false === $theme_name ) {
		$theme_name = wp_get_theme()->get( 'Name' );
	}

	delete_option( 'mods_' . $theme_name );
}

Changelog

Version Description
2.1.0 Introduced.