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!

Bold First Paragraph Content in WordPress

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.

Robert is a seasoned writer and storyteller with a passion for crafting engaging content that resonates with readers. With a background in journalism and a keen eye for detail, he has honed his skills in research and analysis, allowing him to tackle a wide range of topics with ease. Whether exploring the latest trends and innovations or delving into the human experience, Robert's writing is characterized by its clarity, wit, and depth. As a blog writer, he brings his expertise and enthusiasm to the page, creating compelling narratives that inform, inspire, and entertain.

You May Have Missed