Last active
March 17, 2022 00:03
-
-
Save thefuxia/2973189 to your computer and use it in GitHub Desktop.
Replace full content with excerpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php # -*- coding: utf-8 -*- | |
/** | |
* Plugin Name: Replace full content with excerpt | |
* Description: Replaces the full content on post listings with an excerpt | |
* Version: 2012.06.22 | |
* Author: Fuxia Scholz | |
* License: MIT | |
* License URI: http://www.opensource.org/licenses/mit-license.php | |
*/ | |
add_filter( 'the_content', 't5_replace_content_with_excerpt', 100 ); | |
/** | |
* Return excerpt if we are not on a singular post view. | |
* | |
* @param string $content | |
* @return string | |
*/ | |
function t5_replace_content_with_excerpt( $content ) | |
{ | |
if ( is_singular() ) | |
{ | |
return $content; | |
} | |
// remove our filter temporarily. | |
// Otherwise we run into a infinite loop in wp_trim_excerpt(). | |
remove_filter( 'the_content', __FUNCTION__, 100 ); | |
$excerpt = apply_filters( 'the_excerpt', get_the_excerpt() ); | |
add_filter( 'the_content', __FUNCTION__, 100 ); | |
return $excerpt; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
here is what I have to do exactly the contrary, placed in my child theme folder but it does not work