Create a gist now

Instantly share code, notes, and snippets.

Rotating headers plugin for Tarski
Plugin Name: Rotating Headers
Plugin URI:
Description: Rotating headers plugin for Tarski.
Author: Benedict Eastaugh
Version: 1.0
Author URI:
* This function mimics the output of the Tarski function tarski_headerimage,
* albeit using an image randomly chosen from the headers/ directory rather
* than a user-selected image.
* @uses get_tarski_option
* @uses get_bloginfo
function tarski_rotating_headerimage() {
$dir = opendir(TEMPLATEPATH . '/headers');
$headers = array();
while ($current = readdir($dir))
if (($current != 'blank.gif') && !preg_match('/\-thumb\./', $current) && preg_match('/\.(jpg|png|gif)$/', $current))
$headers[] = $current;
$random = rand(0, count($headers) - 1);
$header_img_tag = sprintf('<img alt="%s" src="%s" />',
get_tarski_option('display_title') ? __('Header image', 'tarski') : get_bloginfo('name'),
get_bloginfo('template_directory') . '/headers/' . $headers[$random]);
if (!get_tarski_option('display_title') && !is_front_page())
$header_img_tag = sprintf(
'<a title="%s" rel="home" href="%s">%s</a>',
__('Return to main page', 'tarski'),
echo "<div id=\"header-image\">$header_img_tag</div>\n\n";
* Setup function to work around the plugin/theme initialisation order problem.
* Removes the normal Tarski header image and adds a rotating header instead.
function init_tarski_rotating_headers() {
remove_action('th_header', 'tarski_headerimage');
add_action('th_header', 'tarski_rotating_headerimage', 9);
add_action('init', 'init_tarski_rotating_headers');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment