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
- How can I add multiple ‘tax_query’ arrays via a loop?
- ACF page while loop breaks footer while loop
- Getting a specific post values to another div or modal
- Trying to add attribute to my posts’ featured image
- Output Buffering – Everything between wp_head and wp_print_footer_scripts?
- Displaying the last post on static homepage
- Using foreach loop breaks
- Cannot display or echo alt text on featured image
- Using Advanced Custom Fields to create a per page slider
- Split loop into two columns, how to favor one side over the other
- Can’t get wp_insert_post to work
- Why not yield/iterable in posts interface?
- WordPress Search Results for Multiple Post Types
- Best practice for migration friendly images in posts/pages?
- Showing content from one page on another
- Changing layout with wp_customise
- Display post category in foreach loop with category link
- How to show part of the_content?
- Dynamic Stylesheet loads but doesn’t finish
- Filter Select results based on selection
- Using loop pagination on single.php
- Why WP_Query(‘showposts=5’) shows only 1 post?
- I would like to have different styles for my posts based on the content of each post
- Loop with slider (slider not loading)
- Mass update excerpt
- How to hide all child pages with post_query?
- How to sort posts based on the value (number) of a post’s metadata?
- Show css depending on activity type in BuddyPress activity-loop [closed]
- Unreadable pagination
- 200 Rewrite blog post links
- How to put “Read more” link in Custom Excerpt inside p tag?
- How to set a min number of words for a blog post
- Why my filterable portfolio page work not perfectly between slug button and slug output WORDRPESS?
- Error when adding excerpt to the content through functions.php
- Loop through categories and display posts title under each dropdown
- Get post id in a function when edit/add a post
- how do I get a specific post from a post with a subcategory in WP
- Automatically create child pages and grandchild pages when saving a (parent) page
- wp_trim_words() does not work with my code Am I doing any mistake in my code?
- Removing “wpautop” (auto tags) only on certain pages?
- Second transition_post_status hook fired instead of the first
- Iterate through posts based on array of categories
- get author_name from queried post
- Displaying Woocommerce Product Category in WordPress
- How to store post ID’s in cookie or session to display the same posts later
- Which hook/action will help me solve my problem?
- Increase offset while looping
- Blog posts repeat
- Post + form + action + results on the same page
- How to add condition in wordpress loop? [closed]
- Open post-content in archive page in a Modal box with bootstrap
- Woocommerce : Can’t get product info in loop
- How to set variable, pass it to a partial file and remove it after?
- how to refresh div on template part?
- HTML tags not showing in excerpt
- Alert Bar section within WP loop is displaying even though there are no posts
- Display category name only once inside loop
- Can’t find infinite loop cause
- Checking array against author id in loop
- How do I Turn This Into An if statement?
- Loading index.php contents which located outside blog folder for post single page
- get post content of particular post by url
- Post repeating with infinite scroll
- Custom posts in different columns style
- Get children post mime type using parent post_ID wp_post
- Load wordpress content in other domain
- How to show only subcategories in parent category not parent category?
- How Can I use WP_Query to Only Display 1 Post from Custom Post Type if Query Returns Posts with Matching ID in Custom Field