Created
January 29, 2014 22:51
-
-
Save facelordgists/8698928 to your computer and use it in GitHub Desktop.
PHP output buffering. Great for WordPress shortcodes
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 | |
// generic usage | |
ob_start(); | |
?> | |
<h1>Begin Content</h1> | |
<p>Content</p> | |
<? | |
$ob_str=ob_get_contents(); | |
ob_end_clean(); | |
echo $ob_str; | |
// Example of use in a WordPress Shortcode | |
add_shortcode('shortcode_name','func_shortcode_name'); | |
function func_shortcode_name( $atts, $content = null ) { | |
extract( shortcode_atts( array( | |
'attribute1' => 'default_value', | |
), $atts ) ); | |
ob_start(); | |
?> | |
<h1>Shortcode Output</h1> | |
<p><? echo $attribute1 ?></p> | |
<? | |
$ob_str=ob_get_contents(); | |
ob_end_clean(); | |
return $ob_str; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment