We can try to filter the excerpt through the get_the_excerpt
filter. By default, if we have a manual excerpt, the manual excerpt will be used and not the automatically created excerpt which is created by the wp_trim_excerpt()
function.
We can alter this behavior. What we will do is, when we are inside the main query (in_the_loop()
), we will return the output from the wp_trim_excerpt()
function. This way, we keep all filters as per default. Whenever we are outside the main query, we can return the manually created excerpt, if it exists, otherwise the normal excerpt
add_filter( 'get_the_excerpt', function( $text )
{
if ( in_the_loop() )
return wp_trim_excerpt();
return $text;
});
Related Posts:
- Get excerpt using get_the_excerpt outside a loop
- How can i display the content in plaintext
- How to force excerpts / teasers in the loop
- Exclude filter on front page
- the_excerpt(), get_the_excerpt() and the_content() all killing “the Loop”
- Content/Excerpt length control for a specific loop?
- Combining the_excerpt with the_content
- the_excerpt not showing posts
- Using get_the_excerpt() Before The Loop
- Unable to change the “Read more” text inside the_excerpt
- How to get the excerpt for is_home() outside of the loop isn’t working
- “the_excerpt” in loop just keeps repeating first post?
- Only Show Excerpt After First 3 Posts
- Excerpts not showing on main page
- Excerpt isn’t working or am I missing something?
- to get a little more content after ‘read more’ inside loop
- Limit article to 100 characters. Can’t use the_excerpt…
- Return only content in excerpt field in loop
- How to add excerpt in loop in Twenty Eleven theme?
- Jquery Slider for profile template
- Should I use loop in the single.php file?
- wp_list_categories: get latest featured_image of category
- WordPress Alphabetical Glossary close div in loop
- get_the_foo() in the loop – does it perform another query?
- category__not_in — anyway to use category name instead of id?
- Filtering posts by multiple taxonomies
- Check if date of post is yesterday
- Exclude first 2 posts with meta_key from loop
- Make a custom loop inside single.php with pagination
- Custom excerpt function re-factoring
- How to get_template_part using AJAX?
- How can I modify the loop from a plugin without wiping out other filters?
- I’ve been out of the loop since 2.8. What did I miss?
- Loop first six posts in carousel, next eight in grid
- Complex query and posts pagination
- One custom loop with condition to check child posts
- Loop get_theme_mod
- Move sticky posts down in main loop
- Why only one post (and no pagination) on this variation of the loop?
- Loop in Related Posts WordPress
- Conditional query that displays on Woo product attribute pages
- Template structure
- Custom Loop Using Shortcode in Custom Page Template
- Listing subpages title and content and styling the first iteration differently
- single.php – how to mark current page in the loop
- Cannot retieve the_content() and the_author() – both returning empty strings
- How to order by multiple fields using standard query_posts?
- Get 1 more post in loop
- Make loop alphabetical
- How to check if a product is purchased within the last 365 days before displaying something
- How do I get my loop.php to properly paginate?
- How to get user ID’s from multiple usernames?
- How to display first post
- Pagination on custom post type on front-page.php
- get_template_part() Not Working in Loop
- get_delete_post_link() inside Loop stubbornly returns nothing
- CPT while loop not working
- Problem with Front-Page.php loading recent posts
- Comments_template doesn’t work
- Get markup for post without loading into the template
- Where to add offset?
- How to synchronize The Loop with the max post per page?
- How to add a byline to all the pages?
- Exclude posts based on an array
- Displaying member join date on page
- Ascending order has strange effects on wordpress loop
- List ALL posts by author on author archive
- get post images to link to external sources
- Using is_page_template inside loop
- How to show the last article in a different way in my blog?
- Can’t limit posts_per_page in loop
- Slug is changing when I use WP_Query in a metabox of a post
- How to execute a user loop with shortcode
- Custom loop not working in singular.php, working in other pages
- Loop Posts Outside of WordPress Installation
- Strange problem with wp_get_attachment_image_src database (db) query count
- How to include posts from one category, into a separate category of posts?
- how do i make this loop work
- Archive sorted by month – separate
- Making a specific page wordpress compatable that is not index
- Can’t print out returned value
- change the_content images for different sizes (Desktop, tablet, mobile)?
- Get query result before posts are displayed?
- WordPress Group By Problem
- display only parent replies count in index.php
- using the loop on a page
- Home page loop with pagination problem
- WooCommerce custom loop pagination on front page
- Eliminate duplicates in a foreach loop [closed]
- Tag custom loop show posts
- While loop inside another while loop
- Problem with ms-thumb-frame-selected class in Master Slider
- I want the first post on my home page to be lengthier than the rest (example included)
- Loop with Custom Post Type Taxonomies and Interstitial Code
- Question about custom plugin
- loop mix my child-category and parent-category
- Fix html inside a for loop [closed]
- How can you make it so the comment box shows on some pages or posts but not all?
- Insert multiple custom components after x-number of posts
- Hook in the loop after the first post