Skip to content

Instantly share code, notes, and snippets.

@billerickson
Created September 2, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save billerickson/0c54ab30cb6eaff84b55 to your computer and use it in GitHub Desktop.
Save billerickson/0c54ab30cb6eaff84b55 to your computer and use it in GitHub Desktop.
<?php
add_action( 'load-themes.php', 'genesis_remove_default_widgets_from_header_right' );
/**
* Temporary function to work around the default widgets that get added to
* Header Right when switching themes.
*
* The $defaults array contains a list of the IDs of the widgets that are added
* to the first sidebar in a new default install. If this exactly matches the
* widgets in Header Right after switching themes, then they are removed.
*
* This works around a perceived WP problem for new installs.
*
* If a user amends the list of widgets in the first sidebar before switching to
* a Genesis child theme, then this function won't do anything.
*
* @since 1.8.0
*
* @return null Return early if not just switched to a new theme.
*/
function genesis_remove_default_widgets_from_header_right() {
//* Some tomfoolery for a faux activation hook
if ( ! isset( $_REQUEST['activated'] ) || 'true' !== $_REQUEST['activated'] )
return;
$widgets = get_option( 'sidebars_widgets' );
$defaults = array( 0 => 'search-2', 1 => 'recent-posts-2', 2 => 'recent-comments-2', 3 => 'archives-2', 4 => 'categories-2', 5 => 'meta-2', );
if ( isset( $widgets['header-right'] ) && $defaults === $widgets['header-right'] ) {
$widgets['header-right'] = array();
update_option( 'sidebars_widgets', $widgets );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment