Skip to content

Instantly share code, notes, and snippets.

@techpulsetoday
Created April 18, 2020 11:25
Show Gist options
  • Save techpulsetoday/fcb1e32e05f4ff1d6631e28bfb06c2c8 to your computer and use it in GitHub Desktop.
Save techpulsetoday/fcb1e32e05f4ff1d6631e28bfb06c2c8 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();
*
* @param [type] $content
* @return void
*/
function first_paragraph($content)
{
if (is_page('careers')) {
return preg_replace('/<p([^>]+)?>/', '<p$1 class="text-center">', $content, 1);
} else {
return preg_replace('/<p([^>]+)?>/', '<p$1>', $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