So have you ever wanted to display the current page’s excerpt in the sidebar as a widget? Well, this morning a similar situation arose on how to do this within the Twitter-verse. So, there a couple of us sat thinking and trying to assist in anyway possible. Anyways after a few minutes going back and forth, we had a couple of solutions and one which I coded very quickly into a WordPress Sidebar Widget. The steps taken to find and solve this problem:
- Where is the widget going to be used? The widget with the excerpt should be displayed in the sidebar on single pages and posts.
- Does the Widget need to be installed as a plugin? Or can it simply be an addition to the functions.php of the theme? I decided to be very lazy and coded it directly into the functions.php file of the themes.
After identifying and answering the questions above, I came up with the following solution:
function amcgowanca_widget_show_excerpt() {
if( have_posts() && (is_single() || is_page()) ) {
echo '
' . __('Summary') . '
'; the_excerpt(); echo 'Therefore, to implement and use this widget follow the steps below:
- Copy the above code to your clipboard and paste it into the functions.php file at the bottom (remember to save the file).
- Log in to the WordPress administrative control panel (/wp-admin/) and browse to your ‘Widgets’ panel.
- Simply click, drag and drop the ‘Show page & post excerpt’ function into the sidebar of your choice.
Notes:
- The above code is will not work appropriately with Thematic. Therefore, remove the ‘have_posts() &&’ portion of the if() condition.
- The above source code is licensed under the GNU general public license
- If you have any problems and or questions, please use the comments below to ask and share.

tried it.. have this error message now on my blog
Parse error: syntax error, unexpected T_FUNCTION in /home/nightma/public_html/blog/wp-content/themes/twentyten/functions.php on line 486
i can no longer access any of my blog admin areas- cant sign in, cant view my blog.. no idea what happened.
@Donna:
Hi Donna,
Can you please send me via email (using the contact form above – at http://www.amcgowan.ca/about/contact/ ) an email with your functions.php file. I have a funny feeling that the code above was pasted in the incorrect area. The reason I believe this is because the widget works perfect here on this site and on others.
Thanks.
Aaron McGowan