WordPress sets up a default filter for get_the_excerpt
: wp_trim_excerpt()
. It is this function that will generate an excerpt from the content “if needed”. If you don’t want this behavior, you can just unhook the filter:
add_action( 'init', 'wpse17478_init' );
function wpse17478_init()
{
remove_filter( 'get_the_excerpt', 'wp_trim_excerpt' );
}
Now get_the_excerpt()
will just return the contents of the post_excerpt
database field. If you want to return something when it is empty, you only need to check this case:
add_filter( 'get_the_excerpt', 'wpse17478_get_the_excerpt' );
function wpse17478_get_the_excerpt( $excerpt )
{
if ( '' == $excerpt ) {
return 'No excerpt!';
}
return $excerpt;
}
There is no need to call get_the_excerpt()
– it could even introduce an endless recursion because it applies your filter again!