0

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.

2
  • Solved it :) if(get_the_content()!='') echo get_permalink(); else echo the_excerpt();
    – rakela
    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
    Oct 15, 2014 at 12:49

2 Answers 2

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;
1
  • Aside from a missing ;, you might want to explain why this would solve the question and why you want to add the permalink if the excerpt is empty.
    – kaiser
    Oct 15, 2014 at 13:42
0

You can simply check excerpt via

if(has_excerpt()){
//do your stuff
}else{
//do your stuff
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.