When re-designing my blog I wanted to display the first paragraph of each blog post in bold text. A CSS3 selector could have been used, but wouldn’t work in older browsers such as IE6.
Instead I decided to write a very simple function to add a class name to the first paragraph by filtering the content, then setting the styles accordingly in my theme CSS file.
function first_paragraph($content){ return preg_replace('/<p([^>]+)?>/', '<p$1 class="first">', $content, 1); } add_filter('the_content', 'first_paragraph');
By default this will append class=”first” to the first p tag in your post.
If you want to use this function on your own blog, just add it to your (or create a) functions.php file within your themes folder.
Well done you – not just pretty hair…