We have template tags and some functions that start with get. Sometimes it would be just nice in themes to do like:

$title = the_title();

to use the html later on. This is just a simplified example, naturally there is some function like get_the_title(); But that works for that function only.

I’m wondering why there is no such function like this:

function get_output() {
    $args     = func_get_args();
    $callback = array_shift($args);
    ob_start();
    call_user_func_array($callback, $args);
    return ob_get_clean();
}

That could convert any function that has output into a returning function:

$title = get_output('the_title');

Any idea why about that has never been thought about? Every theme author or hacker can make use of such, right?

3 Answers
3

In direct response to the question, WordPress does not include a function for this partly because it does not specifically apply to WordPress functionality. I.e. it’s a PHP (potential) problem, not WordPress.

Also, I wouldn’t say it’s WordPress’ responsibility to provide workarounds for plugins etc that don’t provide an function to return data (which is against the general WordPress style).

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *