Quick Tip: Bold First Paragraph Content in WordPress
For both style and seo reaasons, having bold first paragraph content in your wordpress website is a smart feature. While searching for a quick and easy to use method of implementing this feature, I came across a handy PHP snippet that makes your first paragraph bold or larger. This PHP snippet works alongside CSS which allows you to style your first paragraph anyway you want!
The PHP snippet below will work with WordPress 3, Â follow the steps below to create this great style feature on your website.
1. Copy and Paste the code below into your functions.php file located in your current WordPress Theme. To easily edit your WordPress Theme go into your Admin Dashboard > Appearance > Editor. Paste the code after <?php.
function first_paragraph($content) { if(is_single()) // make paragraph bold for single pages only { return preg_replace('/<p([^>]+)?>/', '<p$1 class="first_para">', $content, 1); }else{ return $content; } } add_filter('the_content', 'first_paragraph');
2. Lastly add in the CSS code below in your style.css file.
.first_para { font-size:1.1em;font-weight:bold; }
That’s the end of this quick tip tutorial! Special thanks goes to sanwebe.