Skip to content

Instantly share code, notes, and snippets.

@xdissent
Created February 19, 2010 23:55
Show Gist options
  • Save xdissent/309375 to your computer and use it in GitHub Desktop.
Save xdissent/309375 to your computer and use it in GitHub Desktop.
Wrap logo words in spans for Thesis WordPress theme.
<?php
// Override default header.
function custom_default_header() {
// Get the default header.
ob_start();
thesis_default_header();
$output = ob_get_clean();
// Captures the last word in the logo before a tag and its surroundings.
$re = '/( # First subpattern:
logo">[^<\w]* # The h1 or p & up to the next tag or word.
(?:<a[^>]+>)? # A link (maybe?)
[\w\s]* # As many words or spaces as we can handle.
)
( # Second subpattern:
\b\w+ # At least one word.
)
( # Third subpattern:
\s*< # The closing link or logo tag or a span.
)
/x';
// Run the regex replacement until it has no effect.
do {
$previous = $output;
$output = preg_replace($re, '\\1 <span class="word-' . $i . '">\\2</span> \\3', $output);
} while ($previous != $output);
// Output the header with every word in the logo wrapped with a span.
echo $output;
}
remove_action('thesis_hook_header', 'thesis_default_header');
add_action('thesis_hook_header', 'custom_default_header');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment