Best I can tell is that those default widgets get options from the database as their classes are constructed, so there's no way to prevent the DB queries without disabling those widgets entirely. Depending on your needs, you may want that slight performance bump and do not need the widgets, in which case you can use this code to disable them (place in functions.php):
// Remove unneeded widgets that have undesirable query overhead
add_action( 'widgets_init', 'remove_unneeded_widgets' );
function remove_unneeded_widgets() {
unregister_widget('WP_Widget_Pages');
unregister_widget('WP_Widget_Calendar');
unregister_widget('WP_Widget_Tag_Cloud');
unregister_widget('WP_Nav_Menu_Widget');
}
See here for more default widget class names:
http://codex.wordpress.org/Function_Reference/unregister_widget
UPDATE:
I did some more research and discovered that these four widgets do not have any auto-loaded options, even though several other widgets do have auto-loaded options set in the wp_install_defaults()
function in /wp-admin/includes/upgrade.php
. This may be an oversight. In any event, if these widgets have never been loaded into a sidebar, the WP_Widget
parent class or the widget class have never had the opportunity to set any defaults. The other widgets are constructed and use get_option()
but don't produce a query because they're autoloaded with lots of other WordPress options. These four don't have autoloaded options so get_option()
has to query the database for each.
The simplest solution is just to assign defaults when the theme is first activated, like so:
// Clean up widget settings that weren't set at installation
add_action( 'after_switch_theme', 'set_missing_widget_options' );
function set_missing_widget_options( ){
add_option( 'widget_pages', array ( '_multiwidget' => 1 ) );
add_option( 'widget_calendar', array ( '_multiwidget' => 1 ) );
add_option( 'widget_tag_cloud', array ( '_multiwidget' => 1 ) );
add_option( 'widget_nav_menu', array ( '_multiwidget' => 1 ) );
}
single.php
? It's impossible to answer this with the given information.