-
-
Save billerickson/0c54ab30cb6eaff84b55 to your computer and use it in GitHub Desktop.
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( '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