Here's my code inside a widget class:

function widget($args, $instance) {

add_action('wp_footer', function () { echo $instance['title'] });


It doesn't output $instance['title']. I tried passing the $instance parameter in the function, and even tried global $instance;, but neither worked.

  • did you add your function widget to any hook or invoked it?
    – Karun
    Commented Jun 29, 2015 at 4:57
  • It's a part of the widget class I created. Which contains other functions: function update() and function form().
    – Ahmed Saad
    Commented Jun 29, 2015 at 5:01

1 Answer 1


Use the use keyword:

$title = $instance['title'];

add_action( 'wp_footer', function() use ( $title ) {
    echo  $title; 

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.