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 // Post Format support. You can also use the legacy "gallery" or "asides" (note the plural) categories.
81 add_theme_support( 'post-formats', array( 'aside', 'gallery' ) );
83 // This theme uses post thumbnails
84 add_theme_support( 'post-thumbnails' );
86 // Add default posts and comments RSS feed links to head
87 add_theme_support( 'automatic-feed-links' );
89 // Make theme available for translation
90 // Translations can be filed in the /languages/ directory
91 load_theme_textdomain( 'twentyten', TEMPLATEPATH . '/languages' );
93 $locale = get_locale();
94 $locale_file = TEMPLATEPATH . "/languages/$locale.php";
95 if ( is_readable( $locale_file ) )
96 require_once( $locale_file );
98 // This theme uses wp_nav_menu() in one location.
99 register_nav_menus( array(
100 'primary' => __( 'Primary Navigation', 'twentyten' ),
103 // This theme allows users to set a custom background
104 add_custom_background();
106 // Your changeable header business starts here
107 if ( ! defined( 'HEADER_TEXTCOLOR' ) )
108 define( 'HEADER_TEXTCOLOR', '' );
110 // No CSS, just IMG call. The %s is a placeholder for the theme template directory URI.
111 if ( ! defined( 'HEADER_IMAGE' ) )
112 define( 'HEADER_IMAGE', '%s/images/headers/path.jpg' );
114 // The height and width of your custom header. You can hook into the theme's own filters to change these values.
115 // Add a filter to twentyten_header_image_width and twentyten_header_image_height to change these values.
116 define( 'HEADER_IMAGE_WIDTH', apply_filters( 'twentyten_header_image_width', 940 ) );
117 define( 'HEADER_IMAGE_HEIGHT', apply_filters( 'twentyten_header_image_height', 198 ) );
119 // We'll be using post thumbnails for custom header images on posts and pages.
120 // We want them to be 940 pixels wide by 198 pixels tall.
121 // Larger images will be auto-cropped to fit, smaller ones will be ignored. See header.php.
122 set_post_thumbnail_size( HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT, true );
124 // Don't support text inside the header image.
125 if ( ! defined( 'NO_HEADER_TEXT' ) )
126 define( 'NO_HEADER_TEXT', true );
128 // Add a way for the custom header to be styled in the admin panel that controls
129 // custom headers. See twentyten_admin_header_style(), below.
130 add_custom_image_header( '', 'twentyten_admin_header_style' );
132 // ... and thus ends the changeable header business.
134 // Default custom headers packaged with the theme. %s is a placeholder for the theme template directory URI.
135 register_default_headers( array(
137 'url' => '%s/images/headers/berries.jpg',
138 'thumbnail_url' => '%s/images/headers/berries-thumbnail.jpg',
139 /* translators: header image description */
140 'description' => __( 'Berries', 'twentyten' )
142 'cherryblossom' => array(
143 'url' => '%s/images/headers/cherryblossoms.jpg',
144 'thumbnail_url' => '%s/images/headers/cherryblossoms-thumbnail.jpg',
145 /* translators: header image description */
146 'description' => __( 'Cherry Blossoms', 'twentyten' )
149 'url' => '%s/images/headers/concave.jpg',
150 'thumbnail_url' => '%s/images/headers/concave-thumbnail.jpg',
151 /* translators: header image description */
152 'description' => __( 'Concave', 'twentyten' )
155 'url' => '%s/images/headers/fern.jpg',
156 'thumbnail_url' => '%s/images/headers/fern-thumbnail.jpg',
157 /* translators: header image description */
158 'description' => __( 'Fern', 'twentyten' )
160 'forestfloor' => array(
161 'url' => '%s/images/headers/forestfloor.jpg',
162 'thumbnail_url' => '%s/images/headers/forestfloor-thumbnail.jpg',
163 /* translators: header image description */
164 'description' => __( 'Forest Floor', 'twentyten' )
167 'url' => '%s/images/headers/inkwell.jpg',
168 'thumbnail_url' => '%s/images/headers/inkwell-thumbnail.jpg',
169 /* translators: header image description */
170 'description' => __( 'Inkwell', 'twentyten' )
173 'url' => '%s/images/headers/path.jpg',
174 'thumbnail_url' => '%s/images/headers/path-thumbnail.jpg',
175 /* translators: header image description */
176 'description' => __( 'Path', 'twentyten' )
179 'url' => '%s/images/headers/sunset.jpg',
180 'thumbnail_url' => '%s/images/headers/sunset-thumbnail.jpg',
181 /* translators: header image description */
182 'description' => __( 'Sunset', 'twentyten' )
188 if ( ! function_exists( 'twentyten_admin_header_style' ) ) :
190 * Styles the header image displayed on the Appearance > Header admin panel.
192 * Referenced via add_custom_image_header() in twentyten_setup().
194 * @since Twenty Ten 1.0
196 function twentyten_admin_header_style() {
198 <style type="text/css">
199 /* Shows the same border as on front end */
201 border-bottom: 1px solid #000;
202 border-top: 4px solid #000;
204 /* If NO_HEADER_TEXT is false, you would style the text with these selectors:
214 * Get our wp_nav_menu() fallback, wp_page_menu(), to show a home link.
216 * To override this in a child theme, remove the filter and optionally add
217 * your own function tied to the wp_page_menu_args filter hook.
219 * @since Twenty Ten 1.0
221 function twentyten_page_menu_args( $args ) {
222 $args['show_home'] = true;
225 add_filter( 'wp_page_menu_args', 'twentyten_page_menu_args' );
228 * Sets the post excerpt length to 40 characters.
230 * To override this length in a child theme, remove the filter and add your own
231 * function tied to the excerpt_length filter hook.
233 * @since Twenty Ten 1.0
236 function twentyten_excerpt_length( $length ) {
239 add_filter( 'excerpt_length', 'twentyten_excerpt_length' );
242 * Returns a "Continue Reading" link for excerpts
244 * @since Twenty Ten 1.0
245 * @return string "Continue Reading" link
247 function twentyten_continue_reading_link() {
248 return ' <a href="'. get_permalink() . '">' . __( 'Continue reading <span class="meta-nav">→</span>', 'twentyten' ) . '</a>';
252 * Replaces "[...]" (appended to automatically generated excerpts) with an ellipsis and twentyten_continue_reading_link().
254 * To override this in a child theme, remove the filter and add your own
255 * function tied to the excerpt_more filter hook.
257 * @since Twenty Ten 1.0
258 * @return string An ellipsis
260 function twentyten_auto_excerpt_more( $more ) {
261 return ' …' . twentyten_continue_reading_link();
263 add_filter( 'excerpt_more', 'twentyten_auto_excerpt_more' );
266 * Adds a pretty "Continue Reading" link to custom post excerpts.
268 * To override this link in a child theme, remove the filter and add your own
269 * function tied to the get_the_excerpt filter hook.
271 * @since Twenty Ten 1.0
272 * @return string Excerpt with a pretty "Continue Reading" link
274 function twentyten_custom_excerpt_more( $output ) {
275 if ( has_excerpt() && ! is_attachment() ) {
276 $output .= twentyten_continue_reading_link();
280 add_filter( 'get_the_excerpt', 'twentyten_custom_excerpt_more' );
283 * Remove inline styles printed when the gallery shortcode is used.
285 * Galleries are styled by the theme in Twenty Ten's style.css. This is just
286 * a simple filter call that tells WordPress to not use the default styles.
288 * @since Twenty Ten 1.2
290 add_filter( 'use_default_gallery_style', '__return_false' );
293 * Deprecated way to remove inline styles printed when the gallery shortcode is used.
295 * This function is no longer needed or used. Use the use_default_gallery_style
296 * filter instead, as seen above.
298 * @since Twenty Ten 1.0
299 * @deprecated Deprecated in Twenty Ten 1.2 for WordPress 3.1
301 * @return string The gallery style filter, with the styles themselves removed.
303 function twentyten_remove_gallery_css( $css ) {
304 return preg_replace( "#<style type='text/css'>(.*?)</style>#s", '', $css );
306 // Backwards compatibility with WordPress 3.0.
307 if ( version_compare( $GLOBALS['wp_version'], '3.1', '<' ) )
308 add_filter( 'gallery_style', 'twentyten_remove_gallery_css' );
310 if ( ! function_exists( 'twentyten_comment' ) ) :
312 * Template for comments and pingbacks.
314 * To override this walker in a child theme without modifying the comments template
315 * simply create your own twentyten_comment(), and that function will be used instead.
317 * Used as a callback by wp_list_comments() for displaying the comments.
319 * @since Twenty Ten 1.0
321 function twentyten_comment( $comment, $args, $depth ) {
322 $GLOBALS['comment'] = $comment;
323 switch ( $comment->comment_type ) :
326 <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
327 <div id="comment-<?php comment_ID(); ?>">
328 <div class="comment-author vcard">
329 <?php echo get_avatar( $comment, 40 ); ?>
330 <?php printf( __( '%s <span class="says">says:</span>', 'twentyten' ), sprintf( '<cite class="fn">%s</cite>', get_comment_author_link() ) ); ?>
331 </div><!-- .comment-author .vcard -->
332 <?php if ( $comment->comment_approved == '0' ) : ?>
333 <em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'twentyten' ); ?></em>
337 <div class="comment-meta commentmetadata"><a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>">
339 /* translators: 1: date, 2: time */
340 printf( __( '%1$s at %2$s', 'twentyten' ), get_comment_date(), get_comment_time() ); ?></a><?php edit_comment_link( __( '(Edit)', 'twentyten' ), ' ' );
342 </div><!-- .comment-meta .commentmetadata -->
344 <div class="comment-body"><?php comment_text(); ?></div>
347 <?php comment_reply_link( array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
348 </div><!-- .reply -->
349 </div><!-- #comment-## -->
356 <li class="post pingback">
357 <p><?php _e( 'Pingback:', 'twentyten' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __( '(Edit)', 'twentyten' ), ' ' ); ?></p>
365 * Register widgetized areas, including two sidebars and four widget-ready columns in the footer.
367 * To override twentyten_widgets_init() in a child theme, remove the action hook and add your own
368 * function tied to the init hook.
370 * @since Twenty Ten 1.0
371 * @uses register_sidebar
373 function twentyten_widgets_init() {
374 // Area 1, located at the top of the sidebar.
375 register_sidebar( array(
376 'name' => __( 'Primary Widget Area', 'twentyten' ),
377 'id' => 'primary-widget-area',
378 'description' => __( 'The primary 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 2, located below the Primary Widget Area in the sidebar. Empty by default.
386 register_sidebar( array(
387 'name' => __( 'Secondary Widget Area', 'twentyten' ),
388 'id' => 'secondary-widget-area',
389 'description' => __( 'The secondary 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 3, located in the footer. Empty by default.
397 register_sidebar( array(
398 'name' => __( 'First Footer Widget Area', 'twentyten' ),
399 'id' => 'first-footer-widget-area',
400 'description' => __( 'The first 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 4, located in the footer. Empty by default.
408 register_sidebar( array(
409 'name' => __( 'Second Footer Widget Area', 'twentyten' ),
410 'id' => 'second-footer-widget-area',
411 'description' => __( 'The second 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 // Area 5, located in the footer. Empty by default.
419 register_sidebar( array(
420 'name' => __( 'Third Footer Widget Area', 'twentyten' ),
421 'id' => 'third-footer-widget-area',
422 'description' => __( 'The third footer widget area', 'twentyten' ),
423 'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
424 'after_widget' => '</li>',
425 'before_title' => '<h3 class="widget-title">',
426 'after_title' => '</h3>',
429 // Area 6, located in the footer. Empty by default.
430 register_sidebar( array(
431 'name' => __( 'Fourth Footer Widget Area', 'twentyten' ),
432 'id' => 'fourth-footer-widget-area',
433 'description' => __( 'The fourth footer widget area', 'twentyten' ),
434 'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
435 'after_widget' => '</li>',
436 'before_title' => '<h3 class="widget-title">',
437 'after_title' => '</h3>',
440 /** Register sidebars by running twentyten_widgets_init() on the widgets_init hook. */
441 add_action( 'widgets_init', 'twentyten_widgets_init' );
444 * Removes the default styles that are packaged with the Recent Comments widget.
446 * To override this in a child theme, remove the filter and optionally add your own
447 * function tied to the widgets_init action hook.
449 * This function uses a filter (show_recent_comments_widget_style) new in WordPress 3.1
450 * to remove the default style. Using Twenty Ten 1.2 in WordPress 3.0 will show the styles,
451 * but they won't have any effect on the widget in default Twenty Ten styling.
453 * @since Twenty Ten 1.0
455 function twentyten_remove_recent_comments_style() {
456 add_filter( 'show_recent_comments_widget_style', '__return_false' );
458 add_action( 'widgets_init', 'twentyten_remove_recent_comments_style' );
460 if ( ! function_exists( 'twentyten_posted_on' ) ) :
462 * Prints HTML with meta information for the current post-date/time and author.
464 * @since Twenty Ten 1.0
466 function twentyten_posted_on() {
467 printf( __( '<span class="%1$s">Posted on</span> %2$s <span class="meta-sep">by</span> %3$s', 'twentyten' ),
468 'meta-prep meta-prep-author',
469 sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><span class="entry-date">%3$s</span></a>',
471 esc_attr( get_the_time() ),
474 sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s">%3$s</a></span>',
475 get_author_posts_url( get_the_author_meta( 'ID' ) ),
476 sprintf( esc_attr__( 'View all posts by %s', 'twentyten' ), get_the_author() ),
483 if ( ! function_exists( 'twentyten_posted_in' ) ) :
485 * Prints HTML with meta information for the current post (category, tags and permalink).
487 * @since Twenty Ten 1.0
489 function twentyten_posted_in() {
490 // Retrieves tag list of current post, separated by commas.
491 $tag_list = get_the_tag_list( '', ', ' );
493 $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' );
494 } elseif ( is_object_in_taxonomy( get_post_type(), 'category' ) ) {
495 $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' );
497 $posted_in = __( 'Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyten' );
499 // Prints the string, replacing the placeholders.
502 get_the_category_list( ', ' ),
505 the_title_attribute( 'echo=0' )