0

How can I use add_menu_page() functions some variable function ?

add_menu_page('My page','My page','manage_options','my_page', 'func' );

$func = function() {
        echo "Done !";
};

I know I can use like

function func() {
            echo "Done !";
};

But how can I use like

$func = function() {
            echo "Done !";
};

to call it ?

1

You have to declare the closure before you call add_menu_page():

$func = function() {
            echo "Done !";
};

add_menu_page('My page','My page','manage_options','my_page', $func );

Note you need PHP 5.3 to do that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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