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, custom headers and backgrounds, and automatic feed links.
65 * @uses register_nav_menus() To add support for navigation menus.
66 * @uses add_editor_style() To style the visual editor.
67 * @uses load_theme_textdomain() For translation/localization support.
68 * @uses register_default_headers() To register the default custom header images provided with the theme.
69 * @uses set_post_thumbnail_size() To set a custom post thumbnail size.
71 * @since Twenty Ten 1.0
73 function twentyten_setup() {
75 // This theme styles the visual editor with editor-style.css to match the theme style.
78 // Post Format support. You can also use the legacy "gallery" or "asides" (note the plural) categories.
79 add_theme_support( 'post-formats', array( 'aside', 'gallery' ) );
81 // This theme uses post thumbnails
82 add_theme_support( 'post-thumbnails' );
84 // Add default posts and comments RSS feed links to head
85 add_theme_support( 'automatic-feed-links' );
87 // Make theme available for translation
88 // Translations can be filed in the /languages/ directory
89 load_theme_textdomain( 'twentyten', get_template_directory() . '/languages' );
91 // This theme uses wp_nav_menu() in one location.
92 register_nav_menus( array(
93 'primary' => __( 'Primary Navigation', 'twentyten' ),
96 // This theme allows users to set a custom background.
97 add_theme_support( 'custom-background', array(
98 // Let WordPress know what our default background color is.
99 'default-color' => 'f1f1f1',
102 // The custom header business starts here.
104 $custom_header_support = array(
105 // The default image to use.
106 // The %s is a placeholder for the theme template directory URI.
107 'default-image' => '%s/images/headers/path.jpg',
108 // The height and width of our custom header.
109 'width' => apply_filters( 'twentyten_header_image_width', 940 ),
110 'height' => apply_filters( 'twentyten_header_image_height', 198 ),
111 // Support flexible heights.
112 'flex-height' => true,
113 // Don't support text inside the header image.
114 'header-text' => false,
115 // Callback for styling the header preview in the admin.
116 'admin-head-callback' => 'twentyten_admin_header_style',
119 add_theme_support( 'custom-header', $custom_header_support );
121 if ( ! function_exists( 'get_custom_header' ) ) {
122 // This is all for compatibility with versions of WordPress prior to 3.4.
123 define( 'HEADER_TEXTCOLOR', '' );
124 define( 'NO_HEADER_TEXT', true );
125 define( 'HEADER_IMAGE', $custom_header_support['default-image'] );
126 define( 'HEADER_IMAGE_WIDTH', $custom_header_support['width'] );
127 define( 'HEADER_IMAGE_HEIGHT', $custom_header_support['height'] );
128 add_custom_image_header( '', $custom_header_support['admin-head-callback'] );
129 add_custom_background();
132 // We'll be using post thumbnails for custom header images on posts and pages.
133 // We want them to be 940 pixels wide by 198 pixels tall.
134 // Larger images will be auto-cropped to fit, smaller ones will be ignored. See header.php.
135 set_post_thumbnail_size( $custom_header_support['width'], $custom_header_support['height'], true );
137 // ... and thus ends the custom header business.
139 // Default custom headers packaged with the theme. %s is a placeholder for the theme template directory URI.
140 register_default_headers( array(
142 'url' => '%s/images/headers/berries.jpg',
143 'thumbnail_url' => '%s/images/headers/berries-thumbnail.jpg',
144 /* translators: header image description */
145 'description' => __( 'Berries', 'twentyten' )
147 'cherryblossom' => array(
148 'url' => '%s/images/headers/cherryblossoms.jpg',
149 'thumbnail_url' => '%s/images/headers/cherryblossoms-thumbnail.jpg',
150 /* translators: header image description */
151 'description' => __( 'Cherry Blossoms', 'twentyten' )
154 'url' => '%s/images/headers/concave.jpg',
155 'thumbnail_url' => '%s/images/headers/concave-thumbnail.jpg',
156 /* translators: header image description */
157 'description' => __( 'Concave', 'twentyten' )
160 'url' => '%s/images/headers/fern.jpg',
161 'thumbnail_url' => '%s/images/headers/fern-thumbnail.jpg',
162 /* translators: header image description */
163 'description' => __( 'Fern', 'twentyten' )
165 'forestfloor' => array(
166 'url' => '%s/images/headers/forestfloor.jpg',
167 'thumbnail_url' => '%s/images/headers/forestfloor-thumbnail.jpg',
168 /* translators: header image description */
169 'description' => __( 'Forest Floor', 'twentyten' )
172 'url' => '%s/images/headers/inkwell.jpg',
173 'thumbnail_url' => '%s/images/headers/inkwell-thumbnail.jpg',
174 /* translators: header image description */
175 'description' => __( 'Inkwell', 'twentyten' )
178 'url' => '%s/images/headers/path.jpg',
179 'thumbnail_url' => '%s/images/headers/path-thumbnail.jpg',
180 /* translators: header image description */
181 'description' => __( 'Path', 'twentyten' )
184 'url' => '%s/images/headers/sunset.jpg',
185 'thumbnail_url' => '%s/images/headers/sunset-thumbnail.jpg',
186 /* translators: header image description */
187 'description' => __( 'Sunset', 'twentyten' )
193 if ( ! function_exists( 'twentyten_admin_header_style' ) ) :
195 * Styles the header image displayed on the Appearance > Header admin panel.
197 * Referenced via add_custom_image_header() in twentyten_setup().
199 * @since Twenty Ten 1.0
201 function twentyten_admin_header_style() {
203 <style type="text/css">
204 /* Shows the same border as on front end */
206 border-bottom: 1px solid #000;
207 border-top: 4px solid #000;
209 /* If header-text was supported, you would style the text with these selectors:
219 * Get our wp_nav_menu() fallback, wp_page_menu(), to show a home link.
221 * To override this in a child theme, remove the filter and optionally add
222 * your own function tied to the wp_page_menu_args filter hook.
224 * @since Twenty Ten 1.0
226 function twentyten_page_menu_args( $args ) {
227 $args['show_home'] = true;
230 add_filter( 'wp_page_menu_args', 'twentyten_page_menu_args' );
233 * Sets the post excerpt length to 40 characters.
235 * To override this length in a child theme, remove the filter and add your own
236 * function tied to the excerpt_length filter hook.
238 * @since Twenty Ten 1.0
241 function twentyten_excerpt_length( $length ) {
244 add_filter( 'excerpt_length', 'twentyten_excerpt_length' );
247 * Returns a "Continue Reading" link for excerpts
249 * @since Twenty Ten 1.0
250 * @return string "Continue Reading" link
252 function twentyten_continue_reading_link() {
253 return ' <a href="'. get_permalink() . '">' . __( 'Continue reading <span class="meta-nav">→</span>', 'twentyten' ) . '</a>';
257 * Replaces "[...]" (appended to automatically generated excerpts) with an ellipsis and twentyten_continue_reading_link().
259 * To override this in a child theme, remove the filter and add your own
260 * function tied to the excerpt_more filter hook.
262 * @since Twenty Ten 1.0
263 * @return string An ellipsis
265 function twentyten_auto_excerpt_more( $more ) {
266 return ' …' . twentyten_continue_reading_link();
268 add_filter( 'excerpt_more', 'twentyten_auto_excerpt_more' );
271 * Adds a pretty "Continue Reading" link to custom post excerpts.
273 * To override this link in a child theme, remove the filter and add your own
274 * function tied to the get_the_excerpt filter hook.
276 * @since Twenty Ten 1.0
277 * @return string Excerpt with a pretty "Continue Reading" link
279 function twentyten_custom_excerpt_more( $output ) {
280 if ( has_excerpt() && ! is_attachment() ) {
281 $output .= twentyten_continue_reading_link();
285 add_filter( 'get_the_excerpt', 'twentyten_custom_excerpt_more' );
288 * Remove inline styles printed when the gallery shortcode is used.
290 * Galleries are styled by the theme in Twenty Ten's style.css. This is just
291 * a simple filter call that tells WordPress to not use the default styles.
293 * @since Twenty Ten 1.2
295 add_filter( 'use_default_gallery_style', '__return_false' );
298 * Deprecated way to remove inline styles printed when the gallery shortcode is used.
300 * This function is no longer needed or used. Use the use_default_gallery_style
301 * filter instead, as seen above.
303 * @since Twenty Ten 1.0
304 * @deprecated Deprecated in Twenty Ten 1.2 for WordPress 3.1
306 * @return string The gallery style filter, with the styles themselves removed.
308 function twentyten_remove_gallery_css( $css ) {
309 return preg_replace( "#<style type='text/css'>(.*?)</style>#s", '', $css );
311 // Backwards compatibility with WordPress 3.0.
312 if ( version_compare( $GLOBALS['wp_version'], '3.1', '<' ) )
313 add_filter( 'gallery_style', 'twentyten_remove_gallery_css' );
315 if ( ! function_exists( 'twentyten_comment' ) ) :
317 * Template for comments and pingbacks.
319 * To override this walker in a child theme without modifying the comments template
320 * simply create your own twentyten_comment(), and that function will be used instead.
322 * Used as a callback by wp_list_comments() for displaying the comments.
324 * @since Twenty Ten 1.0
326 function twentyten_comment( $comment, $args, $depth ) {
327 $GLOBALS['comment'] = $comment;
328 switch ( $comment->comment_type ) :
331 <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
332 <div id="comment-<?php comment_ID(); ?>">
333 <div class="comment-author vcard">
334 <?php echo get_avatar( $comment, 40 ); ?>
335 <?php printf( __( '%s <span class="says">says:</span>', 'twentyten' ), sprintf( '<cite class="fn">%s</cite>', get_comment_author_link() ) ); ?>
336 </div><!-- .comment-author .vcard -->
337 <?php if ( $comment->comment_approved == '0' ) : ?>
338 <em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'twentyten' ); ?></em>
342 <div class="comment-meta commentmetadata"><a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>">
344 /* translators: 1: date, 2: time */
345 printf( __( '%1$s at %2$s', 'twentyten' ), get_comment_date(), get_comment_time() ); ?></a><?php edit_comment_link( __( '(Edit)', 'twentyten' ), ' ' );
347 </div><!-- .comment-meta .commentmetadata -->
349 <div class="comment-body"><?php comment_text(); ?></div>
352 <?php comment_reply_link( array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
353 </div><!-- .reply -->
354 </div><!-- #comment-## -->
361 <li class="post pingback">
362 <p><?php _e( 'Pingback:', 'twentyten' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __( '(Edit)', 'twentyten' ), ' ' ); ?></p>
370 * Register widgetized areas, including two sidebars and four widget-ready columns in the footer.
372 * To override twentyten_widgets_init() in a child theme, remove the action hook and add your own
373 * function tied to the init hook.
375 * @since Twenty Ten 1.0
376 * @uses register_sidebar
378 function twentyten_widgets_init() {
379 // Area 1, located at the top of the sidebar.
380 register_sidebar( array(
381 'name' => __( 'Primary Widget Area', 'twentyten' ),
382 'id' => 'primary-widget-area',
383 'description' => __( 'The primary widget area', 'twentyten' ),
384 'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
385 'after_widget' => '</li>',
386 'before_title' => '<h3 class="widget-title">',
387 'after_title' => '</h3>',
390 // Area 2, located below the Primary Widget Area in the sidebar. Empty by default.
391 register_sidebar( array(
392 'name' => __( 'Secondary Widget Area', 'twentyten' ),
393 'id' => 'secondary-widget-area',
394 'description' => __( 'The secondary widget area', 'twentyten' ),
395 'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
396 'after_widget' => '</li>',
397 'before_title' => '<h3 class="widget-title">',
398 'after_title' => '</h3>',
401 // Area 3, located in the footer. Empty by default.
402 register_sidebar( array(
403 'name' => __( 'First Footer Widget Area', 'twentyten' ),
404 'id' => 'first-footer-widget-area',
405 'description' => __( 'The first footer widget area', 'twentyten' ),
406 'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
407 'after_widget' => '</li>',
408 'before_title' => '<h3 class="widget-title">',
409 'after_title' => '</h3>',
412 // Area 4, located in the footer. Empty by default.
413 register_sidebar( array(
414 'name' => __( 'Second Footer Widget Area', 'twentyten' ),
415 'id' => 'second-footer-widget-area',
416 'description' => __( 'The second footer widget area', 'twentyten' ),
417 'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
418 'after_widget' => '</li>',
419 'before_title' => '<h3 class="widget-title">',
420 'after_title' => '</h3>',
423 // Area 5, located in the footer. Empty by default.
424 register_sidebar( array(
425 'name' => __( 'Third Footer Widget Area', 'twentyten' ),
426 'id' => 'third-footer-widget-area',
427 'description' => __( 'The third footer widget area', 'twentyten' ),
428 'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
429 'after_widget' => '</li>',
430 'before_title' => '<h3 class="widget-title">',
431 'after_title' => '</h3>',
434 // Area 6, located in the footer. Empty by default.
435 register_sidebar( array(
436 'name' => __( 'Fourth Footer Widget Area', 'twentyten' ),
437 'id' => 'fourth-footer-widget-area',
438 'description' => __( 'The fourth footer widget area', 'twentyten' ),
439 'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
440 'after_widget' => '</li>',
441 'before_title' => '<h3 class="widget-title">',
442 'after_title' => '</h3>',
445 /** Register sidebars by running twentyten_widgets_init() on the widgets_init hook. */
446 add_action( 'widgets_init', 'twentyten_widgets_init' );
449 * Removes the default styles that are packaged with the Recent Comments widget.
451 * To override this in a child theme, remove the filter and optionally add your own
452 * function tied to the widgets_init action hook.
454 * This function uses a filter (show_recent_comments_widget_style) new in WordPress 3.1
455 * to remove the default style. Using Twenty Ten 1.2 in WordPress 3.0 will show the styles,
456 * but they won't have any effect on the widget in default Twenty Ten styling.
458 * @since Twenty Ten 1.0
460 function twentyten_remove_recent_comments_style() {
461 add_filter( 'show_recent_comments_widget_style', '__return_false' );
463 add_action( 'widgets_init', 'twentyten_remove_recent_comments_style' );
465 if ( ! function_exists( 'twentyten_posted_on' ) ) :
467 * Prints HTML with meta information for the current post-date/time and author.
469 * @since Twenty Ten 1.0
471 function twentyten_posted_on() {
472 printf( __( '<span class="%1$s">Posted on</span> %2$s <span class="meta-sep">by</span> %3$s', 'twentyten' ),
473 'meta-prep meta-prep-author',
474 sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><span class="entry-date">%3$s</span></a>',
476 esc_attr( get_the_time() ),
479 sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s">%3$s</a></span>',
480 get_author_posts_url( get_the_author_meta( 'ID' ) ),
481 esc_attr( sprintf( __( 'View all posts by %s', 'twentyten' ), get_the_author() ) ),
488 if ( ! function_exists( 'twentyten_posted_in' ) ) :
490 * Prints HTML with meta information for the current post (category, tags and permalink).
492 * @since Twenty Ten 1.0
494 function twentyten_posted_in() {
495 // Retrieves tag list of current post, separated by commas.
496 $tag_list = get_the_tag_list( '', ', ' );
498 $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' );
499 } elseif ( is_object_in_taxonomy( get_post_type(), 'category' ) ) {
500 $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' );
502 $posted_in = __( 'Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyten' );
504 // Prints the string, replacing the placeholders.
507 get_the_category_list( ', ' ),
510 the_title_attribute( 'echo=0' )