Title: echo vs return
Last modified: January 30, 2018

---

# echo vs return

 *  [bstovold](https://wordpress.org/support/users/bstovold/)
 * (@bstovold)
 * [21 years, 10 months ago](https://wordpress.org/support/topic/echo-vs-return/)
 * Hi folks,
    Just thought I’d share a word about a small frustration I’m having
   with WP. It’s a great tool (I’m currently migrating from MT), and the fact you
   can create your own functions/ plug-ins makes it really extensible. That said,
   if you wanna use internal functions within your own, there seems to be little
   consistency in the way each returns data – sometimes they use `echo` and sometimes
   they use `return`. Of course, that’s not always what you want. On some functions,
   you can pass the parameter `echo="true`, which is great. Alas, it’s not always
   there (on comment_count, for instance), which means you have to copy the internal
   function, hack it about a bit and save it in my_hacks or as part of the plug-
   in. Maybe something to consider going forward – ensure all internal functions
   have a parameter switch for how they output so they can be invoked either in 
   templates, or as part of a plug-in. Just my two cents…

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

 *  [davidhouse](https://wordpress.org/support/users/davidhouse/)
 * (@davidhouse)
 * [21 years, 10 months ago](https://wordpress.org/support/topic/echo-vs-return/#post-69056)
 * Amen. I hate having to hack functions just for that one extra parameter.
 *  [charle97](https://wordpress.org/support/users/charle97/)
 * (@charle97)
 * [21 years, 10 months ago](https://wordpress.org/support/topic/echo-vs-return/#post-69058)
 * i hope the developers don’t waste time on this. i’d rather see the database cleaned
   up of deprecated elements.
 *  Thread Starter [bstovold](https://wordpress.org/support/users/bstovold/)
 * (@bstovold)
 * [21 years, 10 months ago](https://wordpress.org/support/topic/echo-vs-return/#post-69060)
 * I’m not advocating its the only thing that needs improving Charle97. Just that
   its something that’s pretty annoying when you’re trying to write plug-ins or 
   do more complex stuff in the template.
    I certainly wouldn’t say its a “waste[
   of] time”, any more than cleaning up the database. Really just depends on your
   needs. Anyways, this is just a requests/ feedback forum. I’m feeding back 😛
 *  [charle97](https://wordpress.org/support/users/charle97/)
 * (@charle97)
 * [21 years, 10 months ago](https://wordpress.org/support/topic/echo-vs-return/#post-69061)
 * if you know the difference between echo and return, then adding either functionality
   to a function that already uses one is a simple exercise.
 *  [davidhouse](https://wordpress.org/support/users/davidhouse/)
 * (@davidhouse)
 * [21 years, 10 months ago](https://wordpress.org/support/topic/echo-vs-return/#post-69179)
 * bstovold: charle97 meant that hacking a function to make it `return` rather than`
   echo` is a simple process, not that it’s possible without hacking.
    Yes, it’s
   simple, but I think that making WP simpler to use for hackers is something that
   needs to be addressed. Whether that’s having an annotated version available (
   maybe online), or by adding a customary `$echo` paramater, it’s a good idea. 
   Bottom line: it’s easy to hack, but in this instance at least it shouldn’t be
   necessary.
 *  [scottheavner](https://wordpress.org/support/users/scottheavner/)
 * (@scottheavner)
 * [21 years, 10 months ago](https://wordpress.org/support/topic/echo-vs-return/#post-69198)
 * bstovold:
    There’s no need to hack a function to get it to echo its results. 
   Instead of adding echo as a parameter, just put the word “echo” in front of the
   function. As a rule of thumb, I’ve noticed that functions starting with “the_”
   produce output (i.e. they use echo). Any of the others don’t produce output, 
   so you would have to do the echo yourself by placing the word “echo” in front
   of the function call. It’s very easy to make things echo. It’s harder to go the
   other route and get things that are echoing not to. For those it might be useful
   to have a parameter 🙂 Some examples: </pre> the_title(); /* produces output */
   wp_texturize(‘Some text’); /* produces no output */ echo wp_texturize(‘Some text’);/*
   produces output */ </pre>
 *  [davidhouse](https://wordpress.org/support/users/davidhouse/)
 * (@davidhouse)
 * [21 years, 10 months ago](https://wordpress.org/support/topic/echo-vs-return/#post-69326)
 * You don’t necessarily have to change everything when a new version of WordPress
   comes out. I have a file in wp-content/plugins/ that contains all the functions
   I’ve hacked, all with a dmh_ (my initials) prefix to their name. So when I hack
   a function, I’ll copy-paste the code, rename it with the dmh_prefix and then 
   change the code that I need. That way, I can continue to use (or not) these functions
   and the original files in /wp-includes/ remain untouched, ready for upgrade.
 *  [carthik](https://wordpress.org/support/users/carthik/)
 * (@carthik)
 * [21 years, 10 months ago](https://wordpress.org/support/topic/echo-vs-return/#post-69327)
 * …or you could use my-hacks.php to store your functions…
 *  [TechGnome](https://wordpress.org/support/users/techgnome/)
 * (@techgnome)
 * [21 years, 10 months ago](https://wordpress.org/support/topic/echo-vs-return/#post-69340)
 * david – that’s all fine and dandy, unless some new funtionality has been added
   to that function, you won’t get it in your customized version. Granted it depends
   on if you want that new functionality or not.
    TG
 *  Thread Starter [bstovold](https://wordpress.org/support/users/bstovold/)
 * (@bstovold)
 * [21 years, 10 months ago](https://wordpress.org/support/topic/echo-vs-return/#post-69343)
 * Sorry David/2fargon, that’s what I was getting at: if you hack an internal function
   into a plug-in, or in my hacks, if they upgrade or fix ’em, your hacked version
   won’t benefit.
    Once again, it’s not an enormous problem, especially if you’re
   customising or extending the logic beyond recognition. But if you’re just copying
   it out to fix echo/return, it seems a bit silly. Maybe this is something the 
   developers can factor into their coding standards for new routines in future 
   drops. And build it into existing ones as they work on them. As Charles pointed
   out originally, it’s not hard to do…

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

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

 * In: [Requests and Feedback](https://wordpress.org/support/forum/requests-and-feedback/)
 * 10 replies
 * 6 participants
 * Last reply from: [bstovold](https://wordpress.org/support/users/bstovold/)
 * Last activity: [21 years, 10 months ago](https://wordpress.org/support/topic/echo-vs-return/#post-69343)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
