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. /** Make Twenty Eleven available for translation. 
  4. * Translations can be added to the /languages/ directory. 
  5. * If you're building a theme based on Twenty Eleven, use a find and replace 
  6. * to change 'twentyeleven' to the name of your theme in all the template files. 
  7. */ 
  8. load_theme_textdomain( 'twentyeleven', TEMPLATEPATH . '/languages' ); 
  9.  
  10. $locale = get_locale(); 
  11. $locale_file = TEMPLATEPATH . "/languages/$locale.php"; 
  12. if ( is_readable( $locale_file ) ) 
  13. require_once( $locale_file ); 
  14.  
  15. // This theme styles the visual editor with editor-style.css to match the theme style. 
  16. add_editor_style(); 
  17.  
  18. // Load up our theme options page and related code. 
  19. require( dirname( __FILE__ ) . '/inc/theme-options.php' ); 
  20.  
  21. // Grab Twenty Eleven's Ephemera widget. 
  22. require( dirname( __FILE__ ) . '/inc/widgets.php' ); 
  23.  
  24. // Add default posts and comments RSS feed links to <head>. 
  25. add_theme_support( 'automatic-feed-links' ); 
  26.  
  27. // This theme uses wp_nav_menu() in one location. 
  28. register_nav_menu( 'primary', __( 'Primary Menu', 'twentyeleven' ) ); 
  29.  
  30. // Add support for a variety of post formats 
  31. add_theme_support( 'post-formats', array( 'aside', 'link', 'gallery', 'status', 'quote', 'image' ) ); 
  32.  
  33. // Add support for custom backgrounds 
  34. add_custom_background(); 
  35.  
  36. // This theme uses Featured Images (also known as post thumbnails) for per-post/per-page Custom Header images 
  37. add_theme_support( 'post-thumbnails' ); 
  38.  
  39. // The next four constants set how Twenty Eleven supports custom headers. 
  40.  
  41. // The default header text color 
  42. define( 'HEADER_TEXTCOLOR', '000' ); 
  43.  
  44. // By leaving empty, we allow for random image rotation. 
  45. define( 'HEADER_IMAGE', '' ); 
  46.  
  47. // The height and width of your custom header. 
  48. // Add a filter to twentyeleven_header_image_width and twentyeleven_header_image_height to change these values. 
  49. define( 'HEADER_IMAGE_WIDTH', apply_filters( 'twentyeleven_header_image_width', 1000 ) ); 
  50. define( 'HEADER_IMAGE_HEIGHT', apply_filters( 'twentyeleven_header_image_height', 288 ) ); 
  51.  
  52. // We'll be using post thumbnails for custom header images on posts and pages. 
  53. // We want them to be the size of the header image that we just defined 
  54. // Larger images will be auto-cropped to fit, smaller ones will be ignored. See header.php. 
  55. set_post_thumbnail_size( HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT, true ); 
  56.  
  57. // Add Twenty Eleven's custom image sizes 
  58. add_image_size( 'large-feature', HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT, true ); // Used for large feature (header) images 
  59. add_image_size( 'small-feature', 500, 300 ); // Used for featured posts if a large-feature doesn't exist 
  60.  
  61. // Turn on random header image rotation by default. 
  62. add_theme_support( 'custom-header', array( 'random-default' => true ) ); 
  63.  
  64. // Add a way for the custom header to be styled in the admin panel that controls 
  65. // custom headers. See twentyeleven_admin_header_style(), below. 
  66.  
  67. // ... and thus ends the changeable header business. 
  68.  
  69. // Default custom headers packaged with the theme. %s is a placeholder for the theme template directory URI. 
  70. register_default_headers( array( 
  71. 'wheel' => array( 
  72. 'url' => '%s/images/headers/wheel.jpg',  
  73. 'thumbnail_url' => '%s/images/headers/wheel-thumbnail.jpg',  
  74. /** translators: header image description */ 
  75. 'description' => __( 'Wheel', 'twentyeleven' ) 
  76. ),  
  77. 'shore' => array( 
  78. 'url' => '%s/images/headers/shore.jpg',  
  79. 'thumbnail_url' => '%s/images/headers/shore-thumbnail.jpg',  
  80. /** translators: header image description */ 
  81. 'description' => __( 'Shore', 'twentyeleven' ) 
  82. ),  
  83. 'trolley' => array( 
  84. 'url' => '%s/images/headers/trolley.jpg',  
  85. 'thumbnail_url' => '%s/images/headers/trolley-thumbnail.jpg',  
  86. /** translators: header image description */ 
  87. 'description' => __( 'Trolley', 'twentyeleven' ) 
  88. ),  
  89. 'pine-cone' => array( 
  90. 'url' => '%s/images/headers/pine-cone.jpg',  
  91. 'thumbnail_url' => '%s/images/headers/pine-cone-thumbnail.jpg',  
  92. /** translators: header image description */ 
  93. 'description' => __( 'Pine Cone', 'twentyeleven' ) 
  94. ),  
  95. 'chessboard' => array( 
  96. 'url' => '%s/images/headers/chessboard.jpg',  
  97. 'thumbnail_url' => '%s/images/headers/chessboard-thumbnail.jpg',  
  98. /** translators: header image description */ 
  99. 'description' => __( 'Chessboard', 'twentyeleven' ) 
  100. ),  
  101. 'lanterns' => array( 
  102. 'url' => '%s/images/headers/lanterns.jpg',  
  103. 'thumbnail_url' => '%s/images/headers/lanterns-thumbnail.jpg',  
  104. /** translators: header image description */ 
  105. 'description' => __( 'Lanterns', 'twentyeleven' ) 
  106. ),  
  107. 'willow' => array( 
  108. 'url' => '%s/images/headers/willow.jpg',  
  109. 'thumbnail_url' => '%s/images/headers/willow-thumbnail.jpg',  
  110. /** translators: header image description */ 
  111. 'description' => __( 'Willow', 'twentyeleven' ) 
  112. ),  
  113. 'hanoi' => array( 
  114. 'url' => '%s/images/headers/hanoi.jpg',  
  115. 'thumbnail_url' => '%s/images/headers/hanoi-thumbnail.jpg',  
  116. /** translators: header image description */ 
  117. 'description' => __( 'Hanoi Plant', 'twentyeleven' ) 
  118. ) );