Skip to content

Instantly share code, notes, and snippets.

@tommcfarlin
Last active November 23, 2016 16:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tommcfarlin/ce795c15e7b2f7a8ea0797c95da57d0e to your computer and use it in GitHub Desktop.
Save tommcfarlin/ce795c15e7b2f7a8ea0797c95da57d0e to your computer and use it in GitHub Desktop.
[WordPress] Buffering WordPress Content with PHP
<?php
add_filter( 'the_content', 'my_content_filter' );
function my_content_filter( $content ) {
$content .= 'Thanks for wasting your time reading this post!';
return $content;
}
<?php
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 ) {
return;
}
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.
ob_start();
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