Drupal: Add a class to the first non-image paragraph
Say you need to grab the first paragraph of a node’s body that starts out with text. For example, you want to add a drop cap to the first letter of a node’s body, but if the first paragraph only has an image, then you can’t do anything cool like first-child. So here’s what you do.
Throw this into your theme’s template.php:
Replace THEMENAME with your theme’s name (i.e., the name of your theme folder) and you should be good to go. This just adds class=”first” to the first paragraph of your node’s body that does NOT start with an img tag.