K
K
Konstantin2021-06-18 13:46:32
WordPress
Konstantin, 2021-06-18 13:46:32

How to forbid replacing the_excerpt with the_content in case the_excerpt is empty?

I need to do that on the post page, if "Excerpt" (the_excerpt()) is filled, then "excerpt was displayed".
If not, then it didn't show up.

Tried this option:

$my_excerpt = get_the_excerpt();
if ( $my_excerpt ){
  echo $my_excerpt;
}
else {
  echo 'Цитата не установлена.';
}
?>


But if my "Excerpt" is not filled, then it is filled with content from the page (by default in wp, but I don't need this.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem Zolin, 2021-06-18
@gradk

Use has_excerpt(), this function checks if the current post has a short description

if( has_excerpt() ){
  the_excerpt();
} else {
  echo 'Цитата не установлена.';
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question