Styling first paragraphs – functions.php question
-
I’ve separately styled the first paragraphs of my posts using the following in functions.php:
function first_paragraph($content){ return preg_replace('/<p([^>]+)?>/', '<p$1 class="lead">', $content, 1); } add_filter('the_content', 'first_paragraph');
However, very often, the posts have images as the first paragraph – which means that the image paragraph gets the new “class=lead” style (which is useless because it’s just an image), but the actual first text paragraph does not.
What can I do to modify this code so that it will check to see if the first paragraph contains an image, and then ignore that paragraph? What I would like, is to treat the first text-only paragraph as the one that should be styled with “class=lead”.
Any suggestions?
- The topic ‘Styling first paragraphs – functions.php question’ is closed to new replies.