Created
November 17, 2018 20:11
-
-
Save mustafakucuk/cc72c3d353ec9cafb4b034b4c5f889df to your computer and use it in GitHub Desktop.
WordPress add widgets to sidebars during theme activation.
This file contains hidden or 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 | |
// This codes works when theme activate. | |
function switch_theme(){ | |
$widgets = get_option( 'sidebars_widgets' ); | |
$widgets['home_sidebar'] = array( | |
'search-1', // widgetname-1 | |
'text-1', | |
'categories-1', | |
); | |
// widget = prefix | |
// Modify categories widget settings. | |
update_option( 'widget_categories', array( 1 => array( 'title' => 'this is custom title.', 'count' => 'on' ) ) ); | |
// Update sidebars widgets with new settings. | |
update_option( 'sidebars_widgets', $widgets ); | |
} | |
add_action( 'after_switch_theme', 'switch_theme' ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment