Ready to get started?Download WordPress


WordPress functions echo instead of return (2 posts)

  1. davehprohoods
    Posted 10 months 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 9 months 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();


You must log in to post.

About this Topic


No tags yet.