X Theme & Pro Theme

Add the Excerpt to Recent Posts

X Theme & Pro Theme13 Comments

The Recent Posts element in Cornerstone are admittedly lean, but one simple change you can make is to add the post excerpt to them.

While this is something that gets asked frequently, and the code needed to achieve it has been posted by Themeco, many can benefit by having it here. We’re much easier to find than a forum search!

Here’s how you can add excerpts into recent posts.

The following code should be placed in your functions.php file inside your x-child theme.

Furthermore, it’s good to understand how something functions. The code above works by removing the recent posts shortcode from WordPress, and re-initializing it with a new function that pulls the post excerpt from the database and places it into the post box. Finally, you can use CSS to customize the look and feel of the text simply by targeting the .x-recent-posts-excerpt class.

Newsletter

Like what you see? Then get it in your inbox.

  • This field is for validation purposes and should be left unchanged.
Subscribe
Notify of
guest
13 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Amy

When I tried this, I received a “fatal error”:

Fatal error: Call to undefined function csl18n() in /nfs/c03/h06/mnt/56870/domains/MYWEBSITE/html/wp-content/themes/x-child/functions.php on line 93

This is the only thing I have added to the child theme.

Amy

Wow–thank you for responding so quickly! I can only imagine how many of these fixes you will need to find!

That said, I’m still getting the same error using your new code. šŸ™

Amy

Actually that’s alie. Now the error is on line 91:

Fatal error: Call to undefined function csl18n() in /nfs/c03/h06/mnt/56870/domains/MYWEBSITE/html/wp-content/themes/x-child/functions.php on line 91

Amy

It works–you are a genius!!!! Thank you for providing these code tips!

Kevin

Hi!
I was wondering if there was a way to pull in the categories too? I tried just modifying what you have here, but it just pulls text that says “ARRAY”. I haven’t been able to find anything on the forums about adding categories to the recent posts widget.

Erlend

Hi Micheal.

Is there a way to choose the length of the excerpt?

Thanks

Stuart Borders

I have a custom post type of ‘recipes’ that I want to use this for, is there a way to include this PT in the available options for the recent posts.

Michael

Had to update to WordPress 5.5 to work without error, but once I did worked like a charm.