Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm trying to display an excerpt of a page inside an enhanced widget.

I have tried the following but it doesn't work:

<?php
$id = 2550;
$post = get_post($id);
$content = apply_filters('the_content', $post->post_excerpt);
return  $content;
?>
share|improve this question
add comment

1 Answer

Use:

apply_filters( 'get_the_excerpt', $post->post_excerpt )

This will fill the excerpt with the first words from post_content when there is no excerpt, because the default filters will take care of that.

share|improve this answer
    
I get the following error: Parse error: syntax error, unexpected T_RETURN in /var/www/localhost/wp-content/plugins/enhanced-text-widget/enhanced-text-widget.‌​php(53): eval()'d code on line 8 –  James H May 1 '13 at 18:49
    
@JamesH That’s a separate syntax error. –  toscho May 1 '13 at 18:50
    
Any thoughts on how to debug this? –  James H May 1 '13 at 18:58
    
No idea, I don’t know your new source code. Update your question please. –  toscho May 1 '13 at 18:59
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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