Skip to content

Instantly share code, notes, and snippets.

@bonny
Created October 17, 2012 14:21
Show Gist options
  • Save bonny/3905768 to your computer and use it in GitHub Desktop.
Save bonny/3905768 to your computer and use it in GitHub Desktop.
WordPress: Filter to wrap teaser content with a div so we can style the teaser content
/**
* If a page has the more-tag added then wrap the content before the more-tag in a div with the class
* .entry-content-teaser
* this makes it easy for us to style the teaser, like making in bold.
* we hook onto prio 9 instead of 10 so it run before the content has got the tags added
*/
add_filter("the_content", "teasify_the_content", 9);
function teasify_the_content($content) {
if (is_page()) {
if ( preg_match('!<span id="more(.*?)?"></span>!', $content, $matches) ) {
// more-tag-exists, so wrap that in div
$arr_content = explode($matches[0], $content, 2); // [0] = teaser, [1] = content
$content = "<div class='entry-content-teaser'>" . $arr_content[0] . "</div>" . $matches[0] . $arr_content[1];
} else {
// no more-tag, content should just remain content
}
}
return $content;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment