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.
Related Posts:
- Best way of passing PHP variable between partials?
- Custom page with variables in url. Nice url with add_rewrite_rule
- difference between add_object_page and add_menu_page
- How Can I Access a PHP Variable in Another PHP Function
- Is it better to assign functions like get_the_id() to a variable if it’s used multiple times?
- Assigning WP functions which echo to PHP variables
- Passing values from a widget to a function within a plugin
- Using $themename Variables
- How to pass variables from a function in functions.php to an other one
- Define PHP variable from a seperate API if statement
- problem loading stylesheets to wp_head dynamically
- Undefined variable error in new function
- Do I Need to Prefix Variables Inside Functions?
- Updating custom query var with multiple values
- Change Page Title
- get variables data from functions.php to template wordpress (without global variables)
- Getting value of variable from functions.php and debugging it
- Pass post ID from archive template to functions file
- How to access custom class methods from any include without using global
- Using a variable in name of dynamically-called helper function
- Add array of category IDs to global variable?
- Setting a cookie in functions.php and it gets deleted when working on an other function
- getExcerpt: Make ellipsis appear only if character limit is reached
- Using Output from one Function and calling it into another
- How do I access variables outside a function [closed]
- Trying to get this function to show below the content
- add variable to actions/functions across different files (woocommerce)
- Get the ID of the page a menu item links to?
- Add container to nav_menu sub menu
- One Child Functions.php for Multiple Child Themes
- Disabling pingback and trackback notifications
- register_post_type for Pages?
- Paged Single Post doesn’t redirect to the main url after Removing Pagination
- How to get comments with mixed status using get_comments?
- Call to undefined add_action() in theme’s functions.php
- How can I rename the WordPress AJAX URL? [duplicate]
- How to add a rel attribute to images that contains their categories?
- Is it possible to be more page/post specific with admin_enqueue_script?
- What is the most efficient method for loading widgets in functions.php
- Enqueue script o style only if a template part is loaded
- Can I pass two roles to the function get_users?
- Add external js file to footer with id
- password protected post policy
- wp_enqueue JavaScript in child-theme (ReferenceError) using Search & Go
- How can I enable uploading excel files?
- Change the HTML of the comment form that is generating somewhere from the core WordPress
- How to customly read JWPlayer’s “Playlist” items by using its “playlistid”?
- Twentyten Child Theme: header images display messed up in admin panel
- Removing wp_login_viewport_meta
- Get Current Post ID in functions php, meta query filter
- Call WordPress function outside of WordPress
- Move Custom Fields on General Settings Page to New Location
- Remove adjacent_posts_rel_link under 3.2?
- enqueue_script with filemtime javascript not working
- WP function won’t work on 404 template page
- How to obtain the recent posts without their content in an efficient way?
- Limit dimensions of “Full” size images
- Where to put random functions?
- Auto-Tweet if Type is ‘Status’ using OAuth
- Output a specific link in WordPress post if the single post’s category’s name contain certain word
- How to add custom li item to wordpress menu
- Passing user enetered value in widget: number of words, for example
- Adding a section in line at the end of the main navigation menu in php
- How to store a number (coming from cookie) into query vars for later usage in other filters?
- Suggest Users basing on User taxonomy
- Code to insert code into single php
- update_post_meta is Updating with two page id
- Custom Image Size in Insert Media
- Custom function for search form
- Facebook OpenGraph error, Call to undefined function wp_get_attachment_src()
- How to avoid saving empty data to sql while using add_meta_box
- How to assign php file(template) to several pages with same prefix page name/slug
- How to fix Function create_function() is deprecated in / themes
- Block all plug-ins from initiating redirection upon activation?
- How to display my comment count in the wordpress admin bar?
- How Can I Create a Friendly Slug for a Dynamic Page?
- custom error message for empty username and password using authenticate filter not working
- Modifying a WordPress Plugin
- Last updated posts shortcode in functions.php
- I have an fatal error on my funcyions.php
- Get post_author email for Zapier Integration
- get_locale() is different from $locale
- If click on Save/Publish change Post Status to Pending Review instead Publish
- Remove all video attachment, both files and post/postmeta from database?
- Remove the delete link from pages without a plugin
- Custom download page
- HowTo: Add wrapper to columns shortcode?
- How to include a hyperlink in the body text of a custom password protected form?
- Get title from IDs in a string
- uninstall a theme programmaticlly
- Dynamically generated Navigation Diagram using Custom Fields
- Update add_image_size
- Function to get the name in database table from the comma separated string
- Full size image option removing problem
- Limit length of headline in Editor
- Force resize for all video content
- Way of getting queried loop before the query with a filter hook?
- Why my wp_enqueue_script doesnt work on some page?
- Need to use an external variable inside a function
- How to add more than one menu for logged in members?