twentyeleven_setup

Set up theme defaults and registers support for various WordPress features.

Description

twentyeleven_setup(); 

Note that this function is hooked into the after_setup_theme hook, which runs before the init hook. The init hook is too late for some features, such as indicating support post thumbnails.

To override twentyeleven_setup() in a child theme, add your own twentyeleven_setup to your child theme's functions.php file.


Usage

  1. if ( !function_exists( 'twentyeleven_setup' ) ) { 
  2. require_once '/functions.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = twentyeleven_setup(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/functions.php  
  1. function twentyeleven_setup() { 
  2.  
  3. /** 
  4. * Make Twenty Eleven available for translation. 
  5. * Translations can be added to the /languages/ directory. 
  6. * If you're building a theme based on Twenty Eleven, use 
  7. * a find and replace to change 'twentyeleven' to the name 
  8. * of your theme in all the template files. 
  9. */ 
  10. load_theme_textdomain( 'twentyeleven', get_template_directory() . '/languages' ); 
  11.  
  12. // This theme styles the visual editor with editor-style.css to match the theme style. 
  13. add_editor_style(); 
  14.  
  15. // Load up our theme options page and related code. 
  16. require( get_template_directory() . '/inc/theme-options.php' ); 
  17.  
  18. // Grab Twenty Eleven's Ephemera widget. 
  19. require( get_template_directory() . '/inc/widgets.php' ); 
  20.  
  21. // Add default posts and comments RSS feed links to <head>. 
  22. add_theme_support( 'automatic-feed-links' ); 
  23.  
  24. // This theme uses wp_nav_menu() in one location. 
  25. register_nav_menu( 'primary', __( 'Primary Menu', 'twentyeleven' ) ); 
  26.  
  27. // Add support for a variety of post formats 
  28. add_theme_support( 'post-formats', array( 'aside', 'link', 'gallery', 'status', 'quote', 'image' ) ); 
  29.  
  30. $theme_options = twentyeleven_get_theme_options(); 
  31. if ( 'dark' == $theme_options['color_scheme'] ) 
  32. $default_background_color = '1d1d1d'; 
  33. else 
  34. $default_background_color = 'e2e2e2'; 
  35.  
  36. // Add support for custom backgrounds. 
  37. add_theme_support( 'custom-background', array( 
  38. /** 
  39. * Let WordPress know what our default background color is. 
  40. * This is dependent on our current color scheme. 
  41. */ 
  42. 'default-color' => $default_background_color,  
  43. ) ); 
  44.  
  45. // This theme uses Featured Images (also known as post thumbnails) for per-post/per-page Custom Header images 
  46. add_theme_support( 'post-thumbnails' ); 
  47.  
  48. // Add support for custom headers. 
  49. $custom_header_support = array( 
  50. // The default header text color. 
  51. 'default-text-color' => '000',  
  52. // The height and width of our custom header. 
  53. /** 
  54. * Filter the Twenty Eleven default header image width. 
  55. * @since Twenty Eleven 1.0 
  56. * @param int The default header image width in pixels. Default 1000. 
  57. */ 
  58. 'width' => apply_filters( 'twentyeleven_header_image_width', 1000 ),  
  59. /** 
  60. * Filter the Twenty Eleven default header image height. 
  61. * @since Twenty Eleven 1.0 
  62. * @param int The default header image height in pixels. Default 288. 
  63. */ 
  64. 'height' => apply_filters( 'twentyeleven_header_image_height', 288 ),  
  65. // Support flexible heights. 
  66. 'flex-height' => true,  
  67. // Random image rotation by default. 
  68. 'random-default' => true,  
  69. // Callback for styling the header. 
  70. 'wp-head-callback' => 'twentyeleven_header_style',  
  71. // Callback for styling the header preview in the admin. 
  72. 'admin-head-callback' => 'twentyeleven_admin_header_style',  
  73. // Callback used to display the header preview in the admin. 
  74. 'admin-preview-callback' => 'twentyeleven_admin_header_image',  
  75. ); 
  76.  
  77. add_theme_support( 'custom-header', $custom_header_support ); 
  78.  
  79. /** 
  80. * We'll be using post thumbnails for custom header images on posts and pages. 
  81. * We want them to be the size of the header image that we just defined. 
  82. * Larger images will be auto-cropped to fit, smaller ones will be ignored. See header.php. 
  83. */ 
  84. set_post_thumbnail_size( $custom_header_support['width'], $custom_header_support['height'], true ); 
  85.  
  86. /** 
  87. * Add Twenty Eleven's custom image sizes. 
  88. * Used for large feature (header) images. 
  89. */ 
  90. add_image_size( 'large-feature', $custom_header_support['width'], $custom_header_support['height'], true ); 
  91. // Used for featured posts if a large-feature doesn't exist. 
  92. add_image_size( 'small-feature', 500, 300 ); 
  93.  
  94. // Default custom headers packaged with the theme. %s is a placeholder for the theme template directory URI. 
  95. register_default_headers( array( 
  96. 'wheel' => array( 
  97. 'url' => '%s/images/headers/wheel.jpg',  
  98. 'thumbnail_url' => '%s/images/headers/wheel-thumbnail.jpg',  
  99. /** translators: header image description */ 
  100. 'description' => __( 'Wheel', 'twentyeleven' ) 
  101. ),  
  102. 'shore' => array( 
  103. 'url' => '%s/images/headers/shore.jpg',  
  104. 'thumbnail_url' => '%s/images/headers/shore-thumbnail.jpg',  
  105. /** translators: header image description */ 
  106. 'description' => __( 'Shore', 'twentyeleven' ) 
  107. ),  
  108. 'trolley' => array( 
  109. 'url' => '%s/images/headers/trolley.jpg',  
  110. 'thumbnail_url' => '%s/images/headers/trolley-thumbnail.jpg',  
  111. /** translators: header image description */ 
  112. 'description' => __( 'Trolley', 'twentyeleven' ) 
  113. ),  
  114. 'pine-cone' => array( 
  115. 'url' => '%s/images/headers/pine-cone.jpg',  
  116. 'thumbnail_url' => '%s/images/headers/pine-cone-thumbnail.jpg',  
  117. /** translators: header image description */ 
  118. 'description' => __( 'Pine Cone', 'twentyeleven' ) 
  119. ),  
  120. 'chessboard' => array( 
  121. 'url' => '%s/images/headers/chessboard.jpg',  
  122. 'thumbnail_url' => '%s/images/headers/chessboard-thumbnail.jpg',  
  123. /** translators: header image description */ 
  124. 'description' => __( 'Chessboard', 'twentyeleven' ) 
  125. ),  
  126. 'lanterns' => array( 
  127. 'url' => '%s/images/headers/lanterns.jpg',  
  128. 'thumbnail_url' => '%s/images/headers/lanterns-thumbnail.jpg',  
  129. /** translators: header image description */ 
  130. 'description' => __( 'Lanterns', 'twentyeleven' ) 
  131. ),  
  132. 'willow' => array( 
  133. 'url' => '%s/images/headers/willow.jpg',  
  134. 'thumbnail_url' => '%s/images/headers/willow-thumbnail.jpg',  
  135. /** translators: header image description */ 
  136. 'description' => __( 'Willow', 'twentyeleven' ) 
  137. ),  
  138. 'hanoi' => array( 
  139. 'url' => '%s/images/headers/hanoi.jpg',  
  140. 'thumbnail_url' => '%s/images/headers/hanoi-thumbnail.jpg',  
  141. /** translators: header image description */ 
  142. 'description' => __( 'Hanoi Plant', 'twentyeleven' ) 
  143. ) ); 
  144.  
  145. // Indicate widget sidebars can use selective refresh in the Customizer. 
  146. add_theme_support( 'customize-selective-refresh-widgets' );