3 * TwentyTen functions and definitions
5 * Sets up the theme and provides some helper functions. Some helper functions
6 * are used in the theme as custom template tags. Others are attached to action and
7 * filter hooks in WordPress to change core functionality.
9 * The first function, twentyten_setup(), sets up the theme by registering support
10 * for various features in WordPress, such as post thumbnails, navigation menus, and the like.
12 * When using a child theme (see http://codex.wordpress.org/Theme_Development and
13 * http://codex.wordpress.org/Child_Themes), you can override certain functions
14 * (those wrapped in a function_exists() call) by defining them first in your child theme's
15 * functions.php file. The child theme's functions.php file is included before the parent
16 * theme's file, so the child theme functions would be used.
18 * Functions that are not pluggable (not wrapped in function_exists()) are instead attached
19 * to a filter or action hook. The hook can be removed by using remove_action() or
20 * remove_filter() and you can attach your own function to the hook.
22 * We can remove the parent theme's hook only after it is attached, which means we need to
23 * wait until setting up the child theme:
26 * add_action( 'after_setup_theme', 'my_child_theme_setup' );
27 * function my_child_theme_setup() {
28 * // We are providing our own filter for excerpt_length (or using the unfiltered value)
29 * remove_filter( 'excerpt_length', 'twentyten_excerpt_length' );
34 * For more information on hooks, actions, and filters, see http://codex.wordpress.org/Plugin_API.
37 * @subpackage Twenty_Ten
38 * @since Twenty Ten 1.0
42 * Set the content width based on the theme's design and stylesheet.
44 * Used to set the width of images and content. Should be equal to the width the theme
45 * is designed for, generally via the style.css stylesheet.
47 if ( ! isset( $content_width ) )
50 /** Tell WordPress to run twentyten_setup() when the 'after_setup_theme' hook is run. */
51 add_action( 'after_setup_theme', 'twentyten_setup' );
53 if ( ! function_exists( 'twentyten_setup' ) ):
55 * Sets up theme defaults and registers support for various WordPress features.
57 * Note that this function is hooked into the after_setup_theme hook, which runs
58 * before the init hook. The init hook is too late for some features, such as indicating
59 * support post thumbnails.
61 * To override twentyten_setup() in a child theme, add your own twentyten_setup to your child theme's
64 * @uses add_theme_support() To add support for post thumbnails and automatic feed links.
65 * @uses register_nav_menus() To add support for navigation menus.
66 * @uses add_custom_background() To add support for a custom background.
67 * @uses add_editor_style() To style the visual editor.
68 * @uses load_theme_textdomain() For translation/localization support.
69 * @uses add_custom_image_header() To add support for a custom header.
70 * @uses register_default_headers() To register the default custom header images provided with the theme.
71 * @uses set_post_thumbnail_size() To set a custom post thumbnail size.
73 * @since Twenty Ten 1.0
75 function twentyten_setup() {
77 // This theme styles the visual editor with editor-style.css to match the theme style.
80 // This theme uses post thumbnails
81 add_theme_support( 'post-thumbnails' );
83 // Add default posts and comments RSS feed links to head
84 add_theme_support( 'automatic-feed-links' );
86 // Make theme available for translation
87 // Translations can be filed in the /languages/ directory
88 load_theme_textdomain( 'twentyten', TEMPLATEPATH . '/languages' );
90 $locale = get_locale();
91 $locale_file = TEMPLATEPATH . "/languages/$locale.php";
92 if ( is_readable( $locale_file ) )
93 require_once( $locale_file );
95 // This theme uses wp_nav_menu() in one location.
96 register_nav_menus( array(
97 'primary' => __( 'Primary Navigation', 'twentyten' ),
100 // This theme allows users to set a custom background
101 add_custom_background();
103 // Your changeable header business starts here
104 define( 'HEADER_TEXTCOLOR', '' );
105 // No CSS, just IMG call. The %s is a placeholder for the theme template directory URI.
106 define( 'HEADER_IMAGE', '%s/images/headers/path.jpg' );
108 // The height and width of your custom header. You can hook into the theme's own filters to change these values.
109 // Add a filter to twentyten_header_image_width and twentyten_header_image_height to change these values.
110 define( 'HEADER_IMAGE_WIDTH', apply_filters( 'twentyten_header_image_width', 940 ) );
111 define( 'HEADER_IMAGE_HEIGHT', apply_filters( 'twentyten_header_image_height', 198 ) );
113 // We'll be using post thumbnails for custom header images on posts and pages.
114 // We want them to be 940 pixels wide by 198 pixels tall.
115 // Larger images will be auto-cropped to fit, smaller ones will be ignored. See header.php.
116 set_post_thumbnail_size( HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT, true );
118 // Don't support text inside the header image.
119 define( 'NO_HEADER_TEXT', true );
121 // Add a way for the custom header to be styled in the admin panel that controls
122 // custom headers. See twentyten_admin_header_style(), below.
123 add_custom_image_header( '', 'twentyten_admin_header_style' );
125 // ... and thus ends the changeable header business.
127 // Default custom headers packaged with the theme. %s is a placeholder for the theme template directory URI.
128 register_default_headers( array(
130 'url' => '%s/images/headers/berries.jpg',
131 'thumbnail_url' => '%s/images/headers/berries-thumbnail.jpg',
132 /* translators: header image description */
133 'description' => __( 'Berries', 'twentyten' )
135 'cherryblossom' => array(
136 'url' => '%s/images/headers/cherryblossoms.jpg',
137 'thumbnail_url' => '%s/images/headers/cherryblossoms-thumbnail.jpg',
138 /* translators: header image description */
139 'description' => __( 'Cherry Blossoms', 'twentyten' )
142 'url' => '%s/images/headers/concave.jpg',
143 'thumbnail_url' => '%s/images/headers/concave-thumbnail.jpg',
144 /* translators: header image description */
145 'description' => __( 'Concave', 'twentyten' )
148 'url' => '%s/images/headers/fern.jpg',
149 'thumbnail_url' => '%s/images/headers/fern-thumbnail.jpg',
150 /* translators: header image description */
151 'description' => __( 'Fern', 'twentyten' )
153 'forestfloor' => array(
154 'url' => '%s/images/headers/forestfloor.jpg',
155 'thumbnail_url' => '%s/images/headers/forestfloor-thumbnail.jpg',
156 /* translators: header image description */
157 'description' => __( 'Forest Floor', 'twentyten' )
160 'url' => '%s/images/headers/inkwell.jpg',
161 'thumbnail_url' => '%s/images/headers/inkwell-thumbnail.jpg',
162 /* translators: header image description */
163 'description' => __( 'Inkwell', 'twentyten' )
166 'url' => '%s/images/headers/path.jpg',
167 'thumbnail_url' => '%s/images/headers/path-thumbnail.jpg',
168 /* translators: header image description */
169 'description' => __( 'Path', 'twentyten' )
172 'url' => '%s/images/headers/sunset.jpg',
173 'thumbnail_url' => '%s/images/headers/sunset-thumbnail.jpg',
174 /* translators: header image description */
175 'description' => __( 'Sunset', 'twentyten' )
181 if ( ! function_exists( 'twentyten_admin_header_style' ) ) :
183 * Styles the header image displayed on the Appearance > Header admin panel.
185 * Referenced via add_custom_image_header() in twentyten_setup().
187 * @since Twenty Ten 1.0
189 function twentyten_admin_header_style() {
191 <style type="text/css">
192 /* Shows the same border as on front end */
194 border-bottom: 1px solid #000;
195 border-top: 4px solid #000;
197 /* If NO_HEADER_TEXT is false, you would style the text with these selectors:
207 * Get our wp_nav_menu() fallback, wp_page_menu(), to show a home link.
209 * To override this in a child theme, remove the filter and optionally add
210 * your own function tied to the wp_page_menu_args filter hook.
212 * @since Twenty Ten 1.0
214 function twentyten_page_menu_args( $args ) {
215 $args['show_home'] = true;
218 add_filter( 'wp_page_menu_args', 'twentyten_page_menu_args' );
221 * Sets the post excerpt length to 40 characters.
223 * To override this length in a child theme, remove the filter and add your own
224 * function tied to the excerpt_length filter hook.
226 * @since Twenty Ten 1.0
229 function twentyten_excerpt_length( $length ) {
232 add_filter( 'excerpt_length', 'twentyten_excerpt_length' );
235 * Returns a "Continue Reading" link for excerpts
237 * @since Twenty Ten 1.0
238 * @return string "Continue Reading" link
240 function twentyten_continue_reading_link() {
241 return ' <a href="'. get_permalink() . '">' . __( 'Continue reading <span class="meta-nav">→</span>', 'twentyten' ) . '</a>';
245 * Replaces "[...]" (appended to automatically generated excerpts) with an ellipsis and twentyten_continue_reading_link().
247 * To override this in a child theme, remove the filter and add your own
248 * function tied to the excerpt_more filter hook.
250 * @since Twenty Ten 1.0
251 * @return string An ellipsis
253 function twentyten_auto_excerpt_more( $more ) {
254 return ' …' . twentyten_continue_reading_link();
256 add_filter( 'excerpt_more', 'twentyten_auto_excerpt_more' );
259 * Adds a pretty "Continue Reading" link to custom post excerpts.
261 * To override this link in a child theme, remove the filter and add your own
262 * function tied to the get_the_excerpt filter hook.
264 * @since Twenty Ten 1.0
265 * @return string Excerpt with a pretty "Continue Reading" link
267 function twentyten_custom_excerpt_more( $output ) {
268 if ( has_excerpt() && ! is_attachment() ) {
269 $output .= twentyten_continue_reading_link();
273 add_filter( 'get_the_excerpt', 'twentyten_custom_excerpt_more' );
276 * Remove inline styles printed when the gallery shortcode is used.
278 * Galleries are styled by the theme in Twenty Ten's style.css.
280 * @since Twenty Ten 1.0
281 * @return string The gallery style filter, with the styles themselves removed.
283 function twentyten_remove_gallery_css( $css ) {
284 return preg_replace( "#<style type='text/css'>(.*?)</style>#s", '', $css );
286 add_filter( 'gallery_style', 'twentyten_remove_gallery_css' );
288 if ( ! function_exists( 'twentyten_comment' ) ) :
290 * Template for comments and pingbacks.
292 * To override this walker in a child theme without modifying the comments template
293 * simply create your own twentyten_comment(), and that function will be used instead.
295 * Used as a callback by wp_list_comments() for displaying the comments.
297 * @since Twenty Ten 1.0
299 function twentyten_comment( $comment, $args, $depth ) {
300 $GLOBALS['comment'] = $comment;
301 switch ( $comment->comment_type ) :
304 <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
305 <div id="comment-<?php comment_ID(); ?>">
306 <div class="comment-author vcard">
307 <?php echo get_avatar( $comment, 40 ); ?>
308 <?php printf( __( '%s <span class="says">says:</span>', 'twentyten' ), sprintf( '<cite class="fn">%s</cite>', get_comment_author_link() ) ); ?>
309 </div><!-- .comment-author .vcard -->
310 <?php if ( $comment->comment_approved == '0' ) : ?>
311 <em><?php _e( 'Your comment is awaiting moderation.', 'twentyten' ); ?></em>
315 <div class="comment-meta commentmetadata"><a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>">
317 /* translators: 1: date, 2: time */
318 printf( __( '%1$s at %2$s', 'twentyten' ), get_comment_date(), get_comment_time() ); ?></a><?php edit_comment_link( __( '(Edit)', 'twentyten' ), ' ' );
320 </div><!-- .comment-meta .commentmetadata -->
322 <div class="comment-body"><?php comment_text(); ?></div>
325 <?php comment_reply_link( array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
326 </div><!-- .reply -->
327 </div><!-- #comment-## -->
334 <li class="post pingback">
335 <p><?php _e( 'Pingback:', 'twentyten' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __('(Edit)', 'twentyten'), ' ' ); ?></p>
343 * Register widgetized areas, including two sidebars and four widget-ready columns in the footer.
345 * To override twentyten_widgets_init() in a child theme, remove the action hook and add your own
346 * function tied to the init hook.
348 * @since Twenty Ten 1.0
349 * @uses register_sidebar
351 function twentyten_widgets_init() {
352 // Area 1, located at the top of the sidebar.
353 register_sidebar( array(
354 'name' => __( 'Primary Widget Area', 'twentyten' ),
355 'id' => 'primary-widget-area',
356 'description' => __( 'The primary widget area', 'twentyten' ),
357 'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
358 'after_widget' => '</li>',
359 'before_title' => '<h3 class="widget-title">',
360 'after_title' => '</h3>',
363 // Area 2, located below the Primary Widget Area in the sidebar. Empty by default.
364 register_sidebar( array(
365 'name' => __( 'Secondary Widget Area', 'twentyten' ),
366 'id' => 'secondary-widget-area',
367 'description' => __( 'The secondary widget area', 'twentyten' ),
368 'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
369 'after_widget' => '</li>',
370 'before_title' => '<h3 class="widget-title">',
371 'after_title' => '</h3>',
374 // Area 3, located in the footer. Empty by default.
375 register_sidebar( array(
376 'name' => __( 'First Footer Widget Area', 'twentyten' ),
377 'id' => 'first-footer-widget-area',
378 'description' => __( 'The first footer widget area', 'twentyten' ),
379 'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
380 'after_widget' => '</li>',
381 'before_title' => '<h3 class="widget-title">',
382 'after_title' => '</h3>',
385 // Area 4, located in the footer. Empty by default.
386 register_sidebar( array(
387 'name' => __( 'Second Footer Widget Area', 'twentyten' ),
388 'id' => 'second-footer-widget-area',
389 'description' => __( 'The second footer widget area', 'twentyten' ),
390 'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
391 'after_widget' => '</li>',
392 'before_title' => '<h3 class="widget-title">',
393 'after_title' => '</h3>',
396 // Area 5, located in the footer. Empty by default.
397 register_sidebar( array(
398 'name' => __( 'Third Footer Widget Area', 'twentyten' ),
399 'id' => 'third-footer-widget-area',
400 'description' => __( 'The third footer widget area', 'twentyten' ),
401 'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
402 'after_widget' => '</li>',
403 'before_title' => '<h3 class="widget-title">',
404 'after_title' => '</h3>',
407 // Area 6, located in the footer. Empty by default.
408 register_sidebar( array(
409 'name' => __( 'Fourth Footer Widget Area', 'twentyten' ),
410 'id' => 'fourth-footer-widget-area',
411 'description' => __( 'The fourth footer widget area', 'twentyten' ),
412 'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
413 'after_widget' => '</li>',
414 'before_title' => '<h3 class="widget-title">',
415 'after_title' => '</h3>',
418 /** Register sidebars by running twentyten_widgets_init() on the widgets_init hook. */
419 add_action( 'widgets_init', 'twentyten_widgets_init' );
422 * Removes the default styles that are packaged with the Recent Comments widget.
424 * To override this in a child theme, remove the filter and optionally add your own
425 * function tied to the widgets_init action hook.
427 * @since Twenty Ten 1.0
429 function twentyten_remove_recent_comments_style() {
430 global $wp_widget_factory;
431 remove_action( 'wp_head', array( $wp_widget_factory->widgets['WP_Widget_Recent_Comments'], 'recent_comments_style' ) );
433 add_action( 'widgets_init', 'twentyten_remove_recent_comments_style' );
435 if ( ! function_exists( 'twentyten_posted_on' ) ) :
437 * Prints HTML with meta information for the current post—date/time and author.
439 * @since Twenty Ten 1.0
441 function twentyten_posted_on() {
442 printf( __( '<span class="%1$s">Posted on</span> %2$s <span class="meta-sep">by</span> %3$s', 'twentyten' ),
443 'meta-prep meta-prep-author',
444 sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><span class="entry-date">%3$s</span></a>',
446 esc_attr( get_the_time() ),
449 sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s">%3$s</a></span>',
450 get_author_posts_url( get_the_author_meta( 'ID' ) ),
451 sprintf( esc_attr__( 'View all posts by %s', 'twentyten' ), get_the_author() ),
458 if ( ! function_exists( 'twentyten_posted_in' ) ) :
460 * Prints HTML with meta information for the current post (category, tags and permalink).
462 * @since Twenty Ten 1.0
464 function twentyten_posted_in() {
465 // Retrieves tag list of current post, separated by commas.
466 $tag_list = get_the_tag_list( '', ', ' );
468 $posted_in = __( 'This entry was posted in %1$s and tagged %2$s. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyten' );
469 } elseif ( is_object_in_taxonomy( get_post_type(), 'category' ) ) {
470 $posted_in = __( 'This entry was posted in %1$s. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyten' );
472 $posted_in = __( 'Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyten' );
474 // Prints the string, replacing the placeholders.
477 get_the_category_list( ', ' ),
480 the_title_attribute( 'echo=0' )