Title: echo vs. return for WP functions
Last modified: August 18, 2016

---

# echo vs. return for WP functions

 *  [jcornelius](https://wordpress.org/support/users/jcornelius/)
 * (@jcornelius)
 * [21 years, 4 months ago](https://wordpress.org/support/topic/echo-vs-return-for-wp-functions/)
 * I’ve seen a few people talking about this issue but never found an answer.
 * Is there a way (preferably an easy one) to have WP functions like `get_calendar()`,`
   get_links()`, etc… return to a variable instead of echo?
 * This seems like something that would be quite handy and used a lot by people 
   integrating WP into an existing site.
 * Can anyone answer this or at least explain why these functions echo inside the
   class instead of just using `<? echo get_calendar(); ?>` in the template?
 * Functionally, this would work the same as the default `<? get_calendar(); ?>`,
   so why not have a simple way to do it?

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [carthik](https://wordpress.org/support/users/carthik/)
 * (@carthik)
 * [21 years, 4 months ago](https://wordpress.org/support/topic/echo-vs-return-for-wp-functions/#post-127043)
 * Use :
 * `<?php`
 * ob_start();
    the_tag_here(); $my_stuff = ob_get_contents(); ob_end_clean();
 * print($my_stuff); //or whatever else
 * ?>
 * Alex King was the first person I heard talking about something like this, but
   it works, and uses normal php functions. The idea is to buffer the output and
   then use that.
 *  Thread Starter [jcornelius](https://wordpress.org/support/users/jcornelius/)
 * (@jcornelius)
 * [21 years, 4 months ago](https://wordpress.org/support/topic/echo-vs-return-for-wp-functions/#post-127050)
 * Output buffering seems like a sloppy way to go about this though. I agree that
   it will work, but is there not a better way?
 * This introduces several other issues as well. You can’t pass the output of functions
   to other objects, or assign them to templates systems like Smarty as easily.
 * Surely someone out there has a good solution. If not I guess I’ll have to hack
   all the functions myself and post something for the next guy that needs it.
 *  [carthik](https://wordpress.org/support/users/carthik/)
 * (@carthik)
 * [21 years, 4 months ago](https://wordpress.org/support/topic/echo-vs-return-for-wp-functions/#post-127056)
 * There had been some discussion about including variations of the functions that
   return stuff instead of echoing them, at the hackers mailing list.
 * I suppose no one has had the time to modify the files and submit a diff. I will
   look into it as soon as I have an afternoon to spare.
 *  [NuclearMoose](https://wordpress.org/support/users/nuclearmoose/)
 * (@nuclearmoose)
 * [21 years, 4 months ago](https://wordpress.org/support/topic/echo-vs-return-for-wp-functions/#post-127058)
 * **Surely someone out there has a good solution. If not I guess I’ll have to hack
   all the functions myself and post something for the next guy that needs it.**
 * That’s the Open Source way! 🙂

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘echo vs. return for WP functions’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 3 participants
 * Last reply from: [NuclearMoose](https://wordpress.org/support/users/nuclearmoose/)
 * Last activity: [21 years, 4 months ago](https://wordpress.org/support/topic/echo-vs-return-for-wp-functions/#post-127058)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
