Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
WordPress: Add Class to first Paragraph in WordPress the_content; (add this to the functions.php in your Theme)
/* =BEGIN: Add Class to first Paragraph in WordPress the_content();
---------------------------------------------------------------------------------------------------- */
function first_paragraph($content){
// Testing to see if the content is a Page or Custom Post Type of school, if so, display the text normally (without the class = intro).
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