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.

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

Try this one , ..

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

if ( !empty( $excerp ) ) :
else :
    echo get_permalink()
  • 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 '14 at 13:42

You can simply check excerpt via

//do your stuff
//do your stuff

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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