Skip to main content
10 votes
Accepted

Get excerpt from $post->post_content

When in the loop, this will produce excerpt from $post->post_content directly: <?php echo wp_trim_excerpt(); ?> Read more HERE. Alternative Solution: If you are not in the loop, then, you ...
Fayaz's user avatar
  • 8,937
9 votes

Get excerpt using get_the_excerpt outside a loop

Now you can simply use the get_the_excerpt( $postID ) function. Since: WordPress 4.5.0 introduced the $post parameter.
docker's user avatar
  • 159
9 votes
Accepted

wp_trim_words() does not trim the_content() in WordPress

The problem lies in this line: <?php echo wp_trim_words( the_content(), 55, $moreLink); ?> You call the_content function in there. This function prints all the content and doesn't return ...
Krzysiek Dróżdż's user avatar
8 votes

How to remove "read more" link from custom post type excerpt

I fixed this by adding the below to functions.php remove_filter('get_the_excerpt', 'wp_trim_excerpt'); Courtesy of Remove more or [...] text from short post
Rob's user avatar
  • 81
7 votes

Customizing get_the_excerpt() to specific length and "Read More" output.

To get a specific length you can use: wp_trim_words function. It has 3 parameters. Text to trim. Ex: get_the_content() Number of words. Ex: 295 What to append after end of the text. Ex: '' This means ...
Ibrahim Rana's user avatar
6 votes

Remove more or [...] text from short post

As others have already pointed out, using the excerpt_more filter hook is the right way to go. Just wanted to add that you don't have to write a function that returns an empty string. WordPress has a ...
baras's user avatar
  • 61
6 votes
Accepted

Generate a excerpt from an ACF-wysiwyg-field

You can provide your own implementation of wp_trim_excerpt which is responsible for trimming and stripping HTML tags (it uses wp_strip_all_tags), By copying the function source code and applying the ...
Ibrahim Mohamed's user avatar
5 votes
Accepted

Exclude filter on front page

You can just remove the filter before calling the_excerpt and then add it back afterwards... remove_filter('excerpt_more','new_excerpt_more'); the_excerpt(); add_filter('excerpt_more', '...
majick's user avatar
  • 5,091
5 votes
Accepted

Getting first 20 words without excerpt

Use wp_trim_words() wp_trim_words( get_the_content(), 20 ) As you're outside the main loop wp_trim_words( $recent[ 'post_content' ], 20 ) If you want to apply the same filters as to the_content() ...
Nicolai Grossherr's user avatar
5 votes
Accepted

How to change / delete product short description in Woocommerce

Th function wp_set_object_terms() will not work to set post object properties. To add/update/delete product short description there is mainly 2 ways: 1) the WordPress way from a post ID using ...
LoicTheAztec's user avatar
  • 3,321
4 votes
Accepted

Stop strip_shortcodes() stripping content inside shortcodes

Try the filters in your functions.php: add_filter( 'the_excerpt', 'shortcode_unautop'); add_filter( 'the_excerpt', 'do_shortcode'); Props: @bainternet (Source) Or, use your own filter on ...
4 votes
Accepted

My custom get_the_excerpt() can't get excerpt by ID

Try this one /* Change Excerpt length */ function excerpt($num, $post_id) { // removed empty default value $limit = $num+1; $excerpt = apply_filters('the_excerpt', get_post_field('...
MaximOrlovsky's user avatar
4 votes
Accepted

How to Display Post Excerpts in Admin by Default?

The names of unchecked boxes in Screen Options for Edit Post screen are stored in user's meta, per individual user, as an array. Insert the following code in your theme's functions.php: function ...
Frank P. Walentynowicz's user avatar
4 votes

Allow latex in wordpress excerpt

If I'm not mistaken, this could be as simple as add_filter('get_the_excerpt', 'latex_markup'); if the Latex markup isn't removed by another filter before that (it shouldn't, I believe). latex_markup ...
janh's user avatar
  • 2,738
4 votes
Accepted

Custom excerpt length filter doesn't work

For anyone wondering, as custom excerpts don't get trimmed by the excerpt_length filter hook, try adding this filter: function trim_custom_excerpt($excerpt) { if (has_excerpt()) { $...
Fabián Vera's user avatar
3 votes

How to get only manual excerpts?

Answering my own question. Solved with an if else statement using has_excerpt. if( has_excerpt ( $_post, ID ) ) { $author = sprintf( '<a href="%1$s">Apply</a>'...
user93049's user avatar
3 votes

Customizing get_the_excerpt() to specific length and "Read More" output.

You can use this function: function get_excerpt_trim($num_words='20', $more='...'){ $excerpt = get_the_excerpt(); $excerpt = wp_trim_words( $excerpt, $num_words , $more ); return $excerpt;...
ind88's user avatar
  • 31
3 votes

How to include line-breaks in the_excerpt?

wouldn't it be simpler to apply the_content filter to the excerpt? i only use this occasionally, right within the template file: $excerpt = apply_filters('the_content', ( get_post(get_the_ID())->...
diette's user avatar
  • 31
3 votes
Accepted

Do not show excerpt in post content

Don't use the more tag to manually define excerpts. There's a separate input field for that. If it's not visible, go to "screen options" in the upper right corner of the edit screen to enable it. ...
cjbj's user avatar
  • 14.6k
3 votes
Accepted

Adding a character counter to the excerpt metabox

Ok, so I didn't like the way that was written, so i slightly rewrote it with different syntax, and more readable structure. <?php // Add Character Counter to the Excerpt Meta Box function ...
socki03's user avatar
  • 1,932
3 votes

How to Display Post Excerpts in Admin by Default?

Sharing a slight modification of Franks' solution. In my case, I don't want users to ever hide the excerpt so I've hooked the function to the admin_init instead of wp_login. Frank's function ...
Dedering's user avatar
  • 156
3 votes

how to get excerpt without p html tag from wordpress post

Please add below code in theme functions.php remove_filter( 'the_excerpt', 'wpautop' );
Vishit's user avatar
  • 72
3 votes

Generate a excerpt from an ACF-wysiwyg-field

using apply_filters( 'the_excerpt', get_field( 'project_description' ) ); is close, but it's missing a vital step in getting you where you want. the core excerpt builder runs another filter before it ...
mrben522's user avatar
  • 1,673
3 votes
Accepted

Retrieving post excerpt as a shortcode

Just add this to your child theme's functions.php file: add_shortcode( 'output_post_excerpt', 'get_the_excerpt' ); Then use [output_post_excerpt]
sMyles's user avatar
  • 2,846
2 votes

wp_trim_words is trimming by character instead of by words

I think you need to use mb_strimwidth function for trim the characters instead of words. echo mb_strimwidth(get_the_title(), 0, 40, '...');
Syed Figar Ali Jaffri's user avatar
2 votes
Accepted

Shortcodes in RSS excerpts

I tested following code and it worked just fine for me: function my_name_shortcode( $atts ) { return "<h3>PRASAD</h3>"; } add_shortcode( 'name', 'my_name_shortcode' ); add_filter( "...
Prasad Nevase's user avatar
2 votes
Accepted

How to filter out shortcode when displaying the_excerpt() in the loop?

try this add_filter( 'get_the_excerpt', 'strip_shortcodes', 20 ); or try this edit echo strip_shortcodes( get_the_excerpt() ); if shortcode is not register with wordpress function add_shortcode ...
user5200704's user avatar
2 votes
Accepted

Automatic Excerpt Not Working

It turns out my client added shortcodes to the beginning of the posts and the only thing I can think of is that the_excerpt was choosing what words to use from the content before stripping shortcode ...
CSS Apprentice's user avatar
2 votes
Accepted

Twenty Fourteen: Change Read More text

In the twenty fourteen theme there is a plugable function named twentyfourteen_excerpt_more which generates the read more links. This function can be overridden in your child theme to use your custom ...
Aron's user avatar
  • 126

Only top scored, non community-wiki answers of a minimum length are eligible