One option would be to use substr
in your function:
function my_excerpt($limit) {
$excerpt = get_the_excerpt();
if(strlen($excerpt) > $limit) {
// trim to $limit characters
$excerpt = substr($excerpt, 0, $limit);
// remove any truncated words
$excerpt = substr($excerpt, 0, strippos($excerpt, " "));
$excerpt = trim(preg_replace('/\s+/', ' ', $excerpt));
}
return $excerpt;
}
Another way is to filter the excerpt, which will change the length of all your excerpts sitewide:
add_filter('excerpt_length', 'my_excerpt_length');
function my_excerpt_length($length) {
return 30;
}
Related Posts:
- How to Display Post View Count
- Converting a dynamic piece of code using WordPress Loop into a static one using Post ID
- Exclude category from
- Change all author links in Blog roll
- The_excerpt() doesn’t parse – how to change that?
- How to only publish posts with image in it
- Add custom text automatically on each post
- Optimize CPT-function with a loop
- Get post id outside loop : Notice: Trying to get property of non-object
- Show author bio box
- Getting rid of the blog page entirely
- What function does the loop of displaying posts?
- Manually set global $post vars with an ID, in order to use template tags
- Print Current Post Index number within Loop
- Changing the post date and time with function
- Dynamically add id to heading tags
- rewind_posts() – what actually the use of it, and where using is required or preferred?
- How to show list of posts by author and category?
- How to publish a post with empty title and empty content?
- Override the default number of posts to show for a single loop?
- How do I use element instead of tags in WordPress post content having webP support?
- WordPress Number of Posts Not Changing With posts_per_page
- Find most recent authors
- Get the author of the latest revision
- Strange switch_to_blog() issue
- Multiple loops in same page, without duplicate content
- loop not displaying posts on custom template page
- Human Time Diff, change mins to minutes
- How to get new post URL?
- Remove double space after a period
- Displaying the number of posts in a custom loop (without including the number of posts of a loop below)?
- The correct way to call posts with ajax
- How to change the page break URL from ../post/2 to …/post/page2/
- Converting multiple loops into one single loop with pagination
- How would I get 1 latest post from a query for 5 posts?
- Run a function when post is deleted?
- Alternating post layout
- Check to see if specific loop has less than certain amount of posts
- Add icon/badge next to posttitle of specific category
- Adding specific post category between posts in loop
- Multiple loops are not reset
- Blog post per page setting conflicting with custom WP_Query?
- How to exclude latest x posts from a paginated query?
- How do I display some posts fully on the homepage, and some as an excerpt only?
- Post Loop Missing Most Recent Post
- Send post id through ajax and get the post content back
- Start WP Pagination From Number 1 in URL
- Force authors to Preview a post before publishing
- Use two different post_per_page limits with infinite scroll
- Wrong post title displayed from loop
- Get the amount of posts on a current page
- Format latest/newest post differently
- is_page Funtion for Posts ?
- older blog posts not showing in new theme
- How to get posts published on the latest date?
- Page and post loop same template
- WordPress Query Posts From Category Post on Static Page
- Isn’t the way posts are displayed very unefficient?
- restrict incrementation of post vies count when refreshing the page
- Loop through posts? Want to remove extra newlines in actual post HTML/content on backend
- How include css class based on post ( in loop ) slug?
- Get post by tag
- WordPress Loop: How to display recent posts in multiple divs
- Related Posts function not working
- How to display posts on custom page without declaring a posts page in reading settings?
- the_content() Not Grabbing All Content
- Cannot implement byline into posts container in single.php
- Custom WP_Query not working correctly
- saving/reading custom field value does not work – no value gets POSTed
- How come this loop is not working? [closed]
- Internal linking to posts permalink fail because of spaces and stripe at postname
- Have h2 tag not show up if there are no blog posts
- posts going to 2 pages/categories only show up in 1
- WordPress as CMS: How to manage/handle images assigned to a post as full-sized background images in a slideshow?
- Using the loop to set locations for all posts on a single google map
- How to implement a WordPress comments function?
- Separate top level categories on archive-product.php by meta
- While loop in functions.php outputting the_title() of each post on frontpage
- Shortcode for Comments and Comment Boxes in Post Loop
- Display specific posts based on an ID of another post
- How to distinguish pages created by woocommerce?
- Moved a website and excerpts don’t work for old posts
- how to call recent post content in a loop ( only the content before read more tag)
- How to correctly escape data
- Posts are not showing up on next page.
- Post are not showing up
- How to make post button to a random post
- Advanced Post Display/Pagination/Ordering
- Keep post format class with isotope filter
- How to inject a post within a loop
- Sort by category and then date?
- List direct children of page
- Loop not allowing infinite scroll after post per page limit
- Customise the appearance of 4 specific post ID’s within the loop?
- what template-part to call, to have my post in the center of the page?
- How to show only the date, the title and a little “summary” of my WordPress post in my custom theme?
- Display a custom field rating system in the front end
- Ajax calls in wordpress
- posts_per_page – Repeats only first posts ‘post__in’ array
- View post with specific category id and name which I selected in the backend (drop-down option)