Twenty Fourteen: how do they populate by default the sidebar?

In Twenty Fourteen, when you first activate the theme without any changes made to the theme, the widgets that appear there on the sidebar are from the dashboard. You can remove them from Appearance > Widgets and you’ll see Search, Recent Posts, Recent Comments etc. in the meta-box “Primary Sidebar”.

If you want to see the code for the primary sidebar, it’s in the sidebar.php file and looks like this:

<?php if ( is_active_sidebar( 'sidebar-1' ) ) : ?>
<div id="primary-sidebar" class="primary-sidebar widget-area" role="complementary">
    <?php dynamic_sidebar( 'sidebar-1' ); ?>
</div><!-- #primary-sidebar -->
<?php endif; ?>

Also if you’re just curious how WordPress sets up default widgets (in case I misunderstood your question), WordPress does this in a core file in wp-admin/includes/upgrade.php.

Here you’ll find the code that sets up the default widgets on a fresh install of WordPress with a theme. It should look like this on line 234ish:

// Set up default widgets for default theme.
update_option( 'widget_search', array ( 2 => array ( 'title' => '' ), '_multiwidget' => 1 ) );
update_option( 'widget_recent-posts', array ( 2 => array ( 'title' => '', 'number' => 5 ), '_multiwidget' => 1 ) );
update_option( 'widget_recent-comments', array ( 2 => array ( 'title' => '', 'number' => 5 ), '_multiwidget' => 1 ) );
update_option( 'widget_archives', array ( 2 => array ( 'title' => '', 'count' => 0, 'dropdown' => 0 ), '_multiwidget' => 1 ) );
update_option( 'widget_categories', array ( 2 => array ( 'title' => '', 'count' => 0, 'hierarchical' => 0, 'dropdown' => 0 ), '_multiwidget' => 1 ) );
update_option( 'widget_meta', array ( 2 => array ( 'title' => '' ), '_multiwidget' => 1 ) );
update_option( 'sidebars_widgets', array ( 'wp_inactive_widgets' => array (), 'sidebar-1' => array ( 0 => 'search-2', 1 => 'recent-posts-2', 2 => 'recent-comments-2', 3 => 'archives-2', 4 => 'categories-2', 5 => 'meta-2', ), 'array_version' => 3 ) );

Hope that helps. 🙂