How To Display First Paragraph Only Added In Your Posts Via WordPress

As we all know, in WordPress, we can write as many paragraph as we want for our blog post. So, have you ever tried to display first paragraph added in your post out of the content area to showcase it as featured in any way? We think that you might have and could not and hence searched for this. So, after searching for the same about how to accomplish it, you accidentally landed on this page. Well, you are in total luck on this. Here, we will describe about how to display first paragraph added in your WordPress posts or pages.

When to display first paragraph in your site out of content area?

Well, the answer on it depends on about how your site will be structured. If you think that the first paragraph should be always highlighted, then, you can do it. Also, if you want it to highlight it for some featured posts or pages only, then, you can represent it with the checkbox option of enabling or not in your site. So, the requirement for this may vary as per your site need.

How to display first paragraph in your site out of content area?

Well, after knowing about when this feature would be useful for your site, now you may want to integrate it on your site, right? So, why the wait on this to integrate? So, just lets move ahead and paste this below PHP code in the functions.php file of your theme:

Here, in the above code, what we have done is, we have just created the function to display the first paragraph added in your WordPress site. Since, this is function and it is called nowhere at all, hence, it is of no use unless this function is called upon. So, just lets move ahead and then paste this below PHP code in the required file where you want to display it:

Now, after adding the above code, you can see that the first paragraph of the posts or pages created is being shown out of the content area. Also, the screenshot below is the final output of this same feature, when executed on our development environment:

Here, in the above screenshot, you can clearly see that the first paragraph is being highlighted out of the post area of the post, which is in the single post page of same page. Also, you can see that it is repeating in the content area too.

Conclusion

Well, if you have followed up this tutorial properly and was success on displaying the first paragraph of the WordPress post added in your site, then, we can assume that you are more familiar about how to display first paragraph added in your WordPress site than ever before. But, if you are still confused and want more help on this, then, please do drop the comment on the comment box below and we will follow it up.

, , , , , , , , , , , , , , , , , , , , , , ,

Post navigation

Bishal Napit

Bishal Napit is a WordPress theme developer from Tansen, Palpa, with a passion to learn more on WordPress.

Leave a Reply