Created
July 17, 2020 11:36
-
-
Save julian-stark/a9d6b305e20aa28fbc7c2e4743901d63 to your computer and use it in GitHub Desktop.
Wordpress shortcode function: echo vs return
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 | |
// Don't use echo in the shortcodes. If you have to, use ob_start() / return ob_get_clean() | |
add_shortcode('test', 'my_test_func'); | |
function my_test_func( $args ) { | |
ob_start(); | |
?> | |
your content / html / etc | |
<?php | |
return ob_get_clean(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment