trying to stop get_the_excerpt() from defaulting to the_content() if its empty.
this kinda works – well it seems to return ‘xxx’ so i think has_excerpt() isn’t working?
function get_link_excerpt(){
if(has_excerpt()){
$LinkExcerpt = get_the_excerpt();
return $LinkExcerpt."...";
}
return 'no excerpt';
}
add_filter('get_the_excerpt', 'get_link_excerpt');
what’s the best way to control this?
best,Dc
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:Now
get_the_excerpt()
will just return the contents of thepost_excerpt
database field. If you want to return something when it is empty, you only need to check this case:There is no need to call
get_the_excerpt()
– it could even introduce an endless recursion because it applies your filter again!