I use wp_trim_words
to create multiple excerpts. I always abuse it when I need more than one excerpt length. Here is how
function wpse_custom_excerpts($limit) {
return wp_trim_words(get_the_excerpt(), $limit, '<a href="'. esc_url( get_permalink() ) . '">' . ' …' . __( 'Read more »', 'wpse' ) . '</a>');
}
What this function do is taking get_the_excerpt
trimming that to $limit
set by the user and returning the text with a read more link at the end.
You can call this excerpt as follow in your template
echo wpse_custom_excerpts($limit);
where $limit
will be your word count, so an excerpt of 30 word will be
echo wpse_custom_excerpts(30);
Related Posts:
- Problem in replacing the_content with the_excerpt()
- Inject post (from specific category) between posts in Loop
- Automatic Excerpt Not Working
- Go to / Scroll to Password Field on WordPress Posts After Submit With Message(s)
- Extremely slow pageload for long post when using the_content?
- Output 2 items within the Loop
- Custom excerpt function re-factoring
- How to Display a Single Post Excerpt
- How do I Add HTML to the_excerpt() & the_content() Output?
- How can I add extra word in permalink when someone click download button?
- remove post that has no content
- How to avoid duplicates when creating recent network posts
- How to show an entire post content and not also the excerpt?
- What file have I to create in my custom WordPress theme to show all the post belonging to a specific category?
- WordPress query undefined offset in loop
- Only show first image in foreach loop
- Do not duplicate posts with multiple categories in multiple loops
- Need help removing […] after excerpt
- How to pick “full/thumbnail” images in the loop?
- Strip from or something better?
- Wp Query : Order by distance lat,lon
- Give ID to divs inside the loop
- Display articles with a different template in the home page | Solved |
- Is there anyway I can call the year once?
- How do if all posts has this category ID then do this
- Get current_post in reverse order with pagination
- Add div after every 4 posts then every 2 posts for a responsive loop
- Insert div after every three posts in home.php [duplicate]
- Automatically create a loop for post ID
- How to create a loop that will display one post and stop?
- How to use a conditional statement in a post loop but not count towards the “posts_per_page” if false
- Count the number of matching post names in foreach loop
- Limit the Excerpt field in WP-Admin in words
- How to add active class to custom menu using while loop and wp_list_pages
- Print html when custom field has value inside while loop
- post expire after x days
- WordPress Wysiwyg Content not being displayed
- New Plugin Review
- Use template for posts with a particular category grandparent
- Content/Excerpt length control for a specific loop?
- How to change / delete product short description in Woocommerce
- How do I display the function the_content in this loop?
- How to get to a specific position in wp_query?
- Facebook “like” open graph meta in header.php
- “before delete post” action fire when the post is updated?
- Automatically add custom CSS to new posts using a category template
- Displaying the last post on static homepage
- Using foreach loop breaks
- Loop with slider (slider not loading)
- How to hide all child pages with post_query?
- How to sort posts based on the value (number) of a post’s metadata?
- How to put “Read more” link in Custom Excerpt inside p tag?
- Error when adding excerpt to the content through functions.php
- Automatically create child pages and grandchild pages when saving a (parent) page
- Displaying Woocommerce Product Category in WordPress
- Woocommerce : Can’t get product info in loop
- Custom posts in different columns style
- 404 error when I acess the second page of post-type
- My custom get_the_excerpt() can’t get excerpt by ID
- Which PHP page is the Default Posts Page
- Can we count the WordPress Loop
- What are the advantages/disadvantages of using jQuery DOM manipulation as opposed to PHP DOM manipulation?
- Copy taxonomy terms from one post to another programmatically
- Last class on last headline?
- How to catch wordpress post ID when it’s published
- WordPress upload file size error even after raising php limits
- Echoing a CSS class based on category of post in a list
- Php code error in wordpress if else statements [closed]
- pagination broken – clicking next displays “page not found”
- remove specificly the last tag in all posts
- Add posts to custom table in database instead of wp_posts
- How to Create custom block for displaying information in content section which act like shortcode
- How do I get pagination for get_posts() in WordPress or do I have to rewrite the whole code?
- Check if current post in loop is last on current page
- Query on a repeater date (acf)
- Trying to show the category of a post in the post display
- Split post or page content in two or more columns
- Check the database for a postmeta field
- Send POST request to Flask app from functions.php file
- Moved a website and excerpts don’t work for old posts
- Adding PHP to an if else loop
- How to insert text into post based on category – via single.php file
- Generate random access token to a post page
- Filter loop by ‘price’ with meta_query
- Problems with the WordPress loop [closed]
- Only display notification on single post
- Add post class in custom loop (WP_QUERY)
- Get posts associated with media attachment
- Passed variable gets undefined variable error on insert on next page
- Showing content from WordPress ruins page CSS using WP_Query, without, content does not show
- I want my wordpress loop to only display posts of the standard format
- Why does WP_Query show only the same post even with different categories and endwhile?
- why is this content-template not showing any of my blog-entries?
- Trying to display ads on only a third of posts in a loop. Keep getting Error 500?
- How to call the_author_meta and make it work?
- Merging two excerpt functions to work with conditions
- Help with if/else loop [closed]
- Set post to draft if matching word is found in the post
- WooCommerce: write featured image dimensions to custom fields in product’
- transition_post_status hook, works – but not if the post is new