Skip to content

Instantly share code, notes, and snippets.


tommcfarlin/00-the-content.php Secret

Last active Nov 23, 2016
What would you like to do?
[WordPress] Buffering WordPress Content with PHP
add_filter( 'the_content', 'my_content_filter' );
function my_content_filter( $content ) {
$content .= 'Thanks for wasting your time reading this post!';
return $content;
public function init() {
// Grab the ID of the page for which we want to apply the buffered content.
$page_id = $this->get_the_page_ID();
if ( get_the_ID() !== $page_id ) {
add_filter( 'the_content', array( $this, 'the_content' ) );
public function the_content( $content ) {
// Grab the users associated with this installation.
$users = $this->get_users();
// We capture the partial into a buffer so we can append it to the existing content.
include_once 'directory-partial.php';
$content .= ob_get_clean();
return $content;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment