Skip to content

Instantly share code, notes, and snippets.

@gyrus
Last active December 14, 2015 03:18
Show Gist options
  • Save gyrus/5020064 to your computer and use it in GitHub Desktop.
Save gyrus/5020064 to your computer and use it in GitHub Desktop.
Output WordPress content with a class on the first para
<?php
/**
* Output content with a class on the first para
*
* @param string $class Default: 'intro'
* @return void
*/
function pilau_the_content_first_para_class( $class = 'intro' ) {
$content = apply_filters( 'the_content', get_the_content() );
echo preg_replace( '/<p([^>]+)?>/', '<p$1 class="' . $class . '">', $content, 1 );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment