Last active
October 16, 2015 23:44
-
-
Save GhazanfarMir/031d941c20c854040e91 to your computer and use it in GitHub Desktop.
Wordpress - Programmatically deactivate default widgets on theme activation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// add action | |
add_action('after_setup_theme', 'gm_remove_theme_default_widgets' ); | |
/** | |
* function to check if the widgets are already removed by checking options variable | |
* | |
* If the options variable isn't already set assign empty array to `sidebars_widgets` | |
* i.e. storing active widgets | |
*/ | |
function gm_remove_theme_default_widgets() { | |
if ( ! get_option( 'gm_cleared_widgets' ) ) { | |
update_option( 'sidebars_widgets', array() ); | |
update_option( 'gm_cleared_widgets', true ); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment