WordPress functions echo instead of return (2 posts)

  1. davehprohoods
    Posted 2 years ago #

    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?

  2. vtxyzzy
    Posted 2 years ago #

    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();

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.