Skip to content

Instantly share code, notes, and snippets.

@GhazanfarMir
Last active October 16, 2015 23:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save GhazanfarMir/031d941c20c854040e91 to your computer and use it in GitHub Desktop.
Save GhazanfarMir/031d941c20c854040e91 to your computer and use it in GitHub Desktop.
Wordpress - Programmatically deactivate default widgets on theme activation
<?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