Widget development: should I use echo or return on the widget function?
-
I’ve been writing a plugin with a few widgets and using
echoon the widget function to output the contents. However, a friend of mine said I should add the content to a variable and then echo it at the end, since it’s a better practice:function widget { $content = '<div class="row">'; $content .= 'content bla bla bla'; $content .= '</div>'; return $content; }Will this work? What’s your view about that, having in mind PHP but also WordPress conventions?
The topic ‘Widget development: should I use echo or return on the widget function?’ is closed to new replies.