Using the_widget()
is the correct way to “hard code” an arbitrary Widget in a template file:
<?php the_widget( 'foobar_widget', $instance, $args ); ?>
Since the_widget()
simply returns if 'foobar_widget'
is not a registered Widget, it is functionally equivalent to using an if ( function_exists( $function ) )
conditional.
You could look in core to see how the_widget()
verifies 'foobar_widget'
is a registered Widget ( if ! is_a( $widget_obj, 'foobar_widget' ) )
); but really, why bother? Just call the_widget()
. That’s what it’s there for.