Skip to content

Instantly share code, notes, and snippets.

@cwulff
Forked from iscat/functions.php
Created July 3, 2013 14:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cwulff/5918615 to your computer and use it in GitHub Desktop.
Save cwulff/5918615 to your computer and use it in GitHub Desktop.
Add Class to first Paragraph in WordPress the_content();
/* Add Class to first Paragraph in WordPress the_content();
Source: http://webdevbits.com/wordpress/add-class-to-first-paragraph-in-wordpress-the_content/
------------------------------------------------------------------------------------------- */
function first_paragraph($content){
if ( is_page() || ('school' == get_post_type() ) ) {
return preg_replace('/<p([^>]+)?>/', '<p$1>', $content, 1);
} else {
return preg_replace('/<p([^>]+)?>/', '<p$1 class="intro">', $content, 1);
}
}
add_filter('the_content', 'first_paragraph');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment