functions - Check if excerpt is empty at loop-portfolio

admin2025-01-07  7

I want to check if excerpt is not empty, then echo the excerpt link, if not the echo permalink, like this:

if(the_excerpt()!='') echo the_excerpt(); else echo get_permalink() but how can I check if the excerpt field is empty without using the content when empty?

Any help will be appreciated.

I want to check if excerpt is not empty, then echo the excerpt link, if not the echo permalink, like this:

if(the_excerpt()!='') echo the_excerpt(); else echo get_permalink() but how can I check if the excerpt field is empty without using the content when empty?

Any help will be appreciated.

Share Improve this question edited Oct 15, 2014 at 10:14 rakela asked Oct 15, 2014 at 10:07 rakelarakela 101 2
  • Solved it :) if(get_the_content()!='') echo get_permalink(); else echo the_excerpt(); – rakela Commented Oct 15, 2014 at 11:54
  • Welcome to WordPress Development. You can always add your own solution as an answer, but this is not exactly a solution to the stated problem: "check if excerpt is not empty". Please update the question accordingly to avoid confusion ;-) It looks like I misunderstood your question ;-) Notice you don't need the extra echo for the_excerpt(). – birgire Commented Oct 15, 2014 at 12:49
Add a comment  | 

2 Answers 2

Reset to default 0

Try this one , ..

     $ID = get_the_ID();
        $page_data = get_page( $ID );
        $excerp = strip_tags($page_data->post_excerpt);

if ( !empty( $excerp ) ) :
    the_excerpt();
else :
    echo get_permalink()
endif;

You can simply check excerpt via

if(has_excerpt()){
//do your stuff
}else{
//do your stuff
}
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736258747a537.html

最新回复(0)