-
-
Save tommcfarlin/ce795c15e7b2f7a8ea0797c95da57d0e to your computer and use it in GitHub Desktop.
[WordPress] Buffering WordPress Content with PHP
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 | |
add_filter( 'the_content', 'my_content_filter' ); | |
function my_content_filter( $content ) { | |
$content .= 'Thanks for wasting your time reading this post!'; | |
return $content; | |
} |
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 | |
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