In WordPress the_excerpt() displays the excerpt field value of the current post. If you do not provide any content in excerpt field to a post (in the post editor’s optional excerpt field), it will display a teaser which refers to the first 55 words of the post’s content.

Remove excerpt text if excerpt field is empty :

By default, if you have your theme set to display the excerpt and no excerpt content is entered, WordPress will just display the first 55 words teaser from the post. But if you want don’t want anything displayed then simply use the following code in functions.php file.

remove_filter( 'get_the_excerpt', 'wp_trim_excerpt' );

This code will remove the wp_trim_excerpt filter from get_the_excerpt() function.

 

Change WordPress post excerpt length:

You can use excerpt_length filter to set a custom length of the excerpt to display. Remember its the number of words, not number of characters.

function wpboys_change_excerpt_length( $length ) {
// Return a desired excerpt length number
return 150;
}
add_filter( 'excerpt_length', 'wpboys_change_excerpt_length', 999 );

 

Change WordPress excerpt more text[…] :

When an excerpt is displayed you will see characters like this , ” […] ” at the end. You may want to change it to something meaningful, like a readmore link, or simply disable it.

  1. To remove the […] characters from excerpt output , add this filter code in functions.php file.

    add_filter( 'excerpt_more', '__return_empty_string' );

  2. To add a readmore link, we will use the same experpt_more filter as given below. Use the following code in functions.php file of your active theme.

    function wpboys_excerpt_readmore(){
    return '<a href="' . get_the_permalink() . '">Read More »</a>';
    }
    add_filter( 'excerpt_more', 'wpboys_excerpt_readmore', 999 );

If you still have any questions, feel free to leave a comment here, and we will try to help you.