0

I'm setting some options in the backend using functions.php and I'm doing:

$w = the_widget('My_Custom_Widget');

but I don't get any output.

However doing

<?php the_widget('My_Custom_Widget'); ?>

on any page template works fine.

How can I do this?

1 Answer 1

1

The function the_widget() does not return any output it only echos it. If you want to save its output to a variable you need to use output buffering.

ob_start();
the_widget('My_Custom_Widget');
$w = ob_get_contents();
ob_end_clean();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.