Support » How-To and Troubleshooting » WordPress functions echo instead of return

WordPress functions echo instead of return

  • Generally in my experience PHP functions return rather than echo out but WordPress seems to prefer echoing to returning strings or whatever.

    However, there’s been some instances where we wanted to format the string outputted from a WordPress function but it is prevented because it just echoes out whatever instead of letting us handle it. Is there any way to get the functions to return instead of echo?

Viewing 1 replies (of 1 total)
  • Which functions are you talking about? Many of the WP functions have an ‘echo’ parameter that defaults to 1, but you can override that in the function call.

    If the ‘echo’ parameter is not there, you can issue the function call inside ‘ob_start()’ and ‘ob_get_clean()’ calls like this:

    // Call WP function here
    $results = ob_get_clean();
Viewing 1 replies (of 1 total)
  • The topic ‘WordPress functions echo instead of return’ is closed to new replies.
Skip to toolbar