Fix Disappearing Content in Themes plugin fixes a bug found in some themes such as Hybrid based Themes where content and features added by plugins do
The developer of the Hybrid theme system did not agree with me that he should not be calling get_the_excerpt() outside of the content loop. The theme developer was un-cooperative and in so many words told me he could care less about my plugin working with the Hybrid theme. Left with solving the problem in my own plugin, I coded the solution found in this plugin. After testing, I discovered this plugin also fixed the same problem with other plugins and the Hybird Theme system. Since this code could fix problems for other plugins as well as mine, I decided to release it as a separate plugin.
WordPress.org clearly states that calls to the_excerpt() and the_content() must be within the loop. A call to get_the_excerpt() relies upon calling get_the_content() as well as applies the_content filter when the excerpt of a blog post is empty. All of this logic takes place in the wp_trim_excerpt() function in wp-includes/formatting.php. Plugins that use filters for get_the_excerpt, the_excerpt, get_the_content and the_content can be negatively impacted by themes that incorrectly call these functions outside of the content loop.
The excerpt documentation: the_excerpt
Yes. First, do not call the_excerpt(), get_the_excerpt(), the_content() or get_the_content() outside of the content loop. If you do need the excerpt, the most efficient way to get the excerpt or the content is to obtain it directly from the global $post object. The advantage of obtaining the content or the excerpt from the global post object is that you do not have to worry about WordPress cutting the string length at 55 words, adding an undesired [...] to the end of the excerpt, and you can brag that your theme is efficient in that it does not require WordPress to iterate through additional filters which can be process intensive and use precious system memory.
Below is an example function you can add to your theme's functions.php and call when you want to obtain the excerpt outside of the content loop.
function mythemename_get_the_excerpt($excerpt_word_count=55)
{
global $post;
$excerpt = $post->post_excerpt;
if( $excerpt == '' )
{
$excerpt = $post->post_content;
$excerpt = strip_shortcodes( $excerpt );
$excerpt = str_replace(']]>', ']]>', $excerpt);
$excerpt = strip_tags($excerpt);
}
$words = explode(' ', $excerpt, $excerpt_word_count + 1);
if (count($words) > $excerpt_length) {
array_pop($words);
$excerpt = implode(' ', $words);
}
return $excerpt;
}
The description may be obtained simply by referring to the $post object.
echo $post->post_content;
Requires: 2.0 or higher
Compatible up to: 2.8.4
Last Updated: 2009-9-29
Downloads: 795
Got something to say? Need help?