Image Rotator for the Header of Twentyten

The wp3 default theme TwentyTen comes with a choice of header images, which can be selected from the dashboard.
To rotate these images to show randomly in the header, we can make use of the global array variable which stores all the default header image information: $_wp_default_headers.

The rest is easy: we build a function, which we later save in functions.php of TwentyTen, to pick a random image out of the available images:

function rotate_default_headers() {
global $_wp_default_headers;
$rnd_header = rand( 1,count($_wp_default_headers));
$header_nr = 1;
foreach( $_wp_default_headers as $heady ) :
if ( $header_nr == $rnd_header ) {
echo get_bloginfo('template_url') . substr( $heady['url'], 2 );
break;
}
$header_nr++;
endforeach;
}

to show the randomly rotated images in the header, add the function call in header.php –
simply edit header.php, and find this line:

<img src="<?php header_image(); ?>" width="<?php echo HEADER_IMAGE_WIDTH; ?>" height="<?php echo HEADER_IMAGE_HEIGHT; ?>" alt="" />

expand it to accomodate the function call:

<img src="<?php if (function_exists('rotate_default_headers')) rotate_default_headers(); else header_image(); ?>" width="<?php echo HEADER_IMAGE_WIDTH; ?>" height="<?php echo HEADER_IMAGE_HEIGHT; ?>" alt="" />

done – now you will have a different header image each time you switch to a new page (within the limitions of statistics, of course).

Automatically Shorten the Manual Excerpt

When you are building or modifying a wordpress theme, you have the choice of either using ‘the_content()’ to show the full article, or ‘the_excerpt()’ to show a shorter version.
By default, the latter limits the output to the first 55 words of the post, and automatcally strips formatting and images.
To make things more flexible, the editor also allows you to add a manual excerpt that will have preference before the automatically generated one.
There is no default limit to the length of this manual excerpt, which might break some carefully designed templates.

To apply the excerpt length limit to all excerpts, a modification of a core wordpress function ‘wp_trim_excerpt()’ would be needed.
However, changing core files is not a good idea, as the changes will be lost after each update.

Luckily, the same result can be achieved by using a fillter hook on ‘get_the_excerpt’; the code for it is added to functions.php of the theme.

(updated to utilize the filters ‘excert_length’ and ‘excerpt_more’ – aug 2010)

function wp_trim_all_excerpt($text) {
// Creates an excerpt if needed; and shortens the manual excerpt as well
global $post;
  $raw_excerpt = $text;
  if ( '' == $text ) {
    $text = get_the_content('');
    $text = strip_shortcodes( $text );
    $text = apply_filters('the_content', $text);
    $text = str_replace(']]>', ']]&gt;', $text);
  }

$text = strip_tags($text);
$excerpt_length = apply_filters('excerpt_length', 55);
$excerpt_more = apply_filters('excerpt_more', ' ' . '[...]');
$text = wp_trim_words( $text, $excerpt_length, $excerpt_more ); //since wp3.3
/*$words = explode(' ', $text, $excerpt_length + 1);
  if (count($words)> $excerpt_length) {
    array_pop($words);
    $text = implode(' ', $words);
    $text = $text . $excerpt_more;
  } else {
    $text = implode(' ', $words);
  }
return $text;*/
return apply_filters('wp_trim_excerpt', $text, $raw_excerpt); //since wp3.3
}

remove_filter('get_the_excerpt', 'wp_trim_excerpt');
add_filter('get_the_excerpt', 'wp_trim_all_excerpt');

edit: expanded to take remove shortcode from the excerpt; 12/07/2010
edit: adapted to wp3.3; 16.01.2012

thanks to michael.oeser for his well written article: Wie man WordPress Textauszüge mit the_excerpt individuell anpasst. It contains even more details on how to tweak the excerpt.