I need to automatically bold the first paragraph of each article for every post on my blog, but not sure how to do so. Any ideas? Thanks.
I need to automatically bold the first paragraph of each article for every post on my blog, but not sure how to do so. Any ideas? Thanks.
You can use CSS3 :first-child pseudo-class to achieve this.
http://www.w3schools.com/css/pr_pseudo_first-child.asp
It won't work in IE and old browsers though.
1. Automatically add a class (e.g.: class="lead") to your first paragraph, you can do it this way:
function first_paragraph($content){
return preg_replace('/<p([^>]+)?>/', '<p$1 class="lead">', $content, 1);
}
add_filter('the_content', 'first_paragraph');
2. In your style sheet add:
p.lead {
font-weight: bold;
}Not working at all for me.
I know that the code is being parsed because when I took the <?php bit off of the front end of the file the contents of the file showed up at the top of my site.
My mistake! It was a conflict with a plugin that was preventing the function from formatting the post.
This topic has been closed to new replies.