Title: adding function arguments to add_action
Last modified: August 19, 2016

---

# adding function arguments to add_action

 *  [pwdrskier4](https://wordpress.org/support/users/pwdrskier4/)
 * (@pwdrskier4)
 * [18 years, 4 months ago](https://wordpress.org/support/topic/adding-function-arguments-to-add_action/)
 * How do I send a argument(s) to my function when calling it from add_action? I
   have tried many, many ways and can not get it to work.
 *     ```
       add_action('admin_menu', 'mt_add_pages');
   
       function mt_add_pages($name) {
   
           add_menu_page($name, $name, 0, __FILE__, 'mt_toplevel_page');
   
       }
   
       function mt_toplevel_page() {
           echo "<h2>Edit Listing</h2>";
       }
       ```
   

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [whooami](https://wordpress.org/support/users/whooami/)
 * (@whooami)
 * [18 years, 4 months ago](https://wordpress.org/support/topic/adding-function-arguments-to-add_action/#post-691859)
 *     ```
       function myfunky_function() {
       	echo "hello";
       }
       ```
   
 *     ```
       function user_menu () {
       	add_users_page('menu', 'menu', 1, basename(__FILE__), 'myfunky_function');
       }
       ```
   
 * `add_action('admin_menu', 'user_menu');`
 * works for me.
 *  Thread Starter [pwdrskier4](https://wordpress.org/support/users/pwdrskier4/)
 * (@pwdrskier4)
 * [18 years, 4 months ago](https://wordpress.org/support/topic/adding-function-arguments-to-add_action/#post-691874)
 * Okay, I think you may have missed what I am getting at. From your example, I 
   would be trying to pass a variable to myfunky_function when I called it. So that
   it is something like this:
 *     ```
       function myfunky_function($text) {
       	echo $text;
       }
   
       function user_menu () {
       	add_users_page('menu', 'menu', 1, basename(__FILE__), 'myfunky_function($text-to-pass)');
       }
   
       add_action('admin_menu', 'user_menu');
       ```
   
 * Basically I am trying to make myfunky_function($text-to-pass) work.
 * Does that make sense? Any suggestions?
 *  [whooami](https://wordpress.org/support/users/whooami/)
 * (@whooami)
 * [18 years, 4 months ago](https://wordpress.org/support/topic/adding-function-arguments-to-add_action/#post-691875)
 * I might still be misunderstanding, but if you are trying to pass a variable to
   your function, you need to make it a global.
 *  [jaysonng](https://wordpress.org/support/users/jaysonng/)
 * (@jaysonng)
 * [18 years, 2 months ago](https://wordpress.org/support/topic/adding-function-arguments-to-add_action/#post-692075)
 * any update on this? can no one answer this supposedly easy thing if it were straight
   php?
 * wordpress is making it hard .
 * can I use
 *     ```
       add_action('action_here', 'function_name($variable)');
       ```
   
 * to work?

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘adding function arguments to add_action’ is closed to new replies.

## Tags

 * [add_action](https://wordpress.org/support/topic-tag/add_action/)
 * [functions](https://wordpress.org/support/topic-tag/functions/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 3 participants
 * Last reply from: [jaysonng](https://wordpress.org/support/users/jaysonng/)
 * Last activity: [18 years, 2 months ago](https://wordpress.org/support/topic/adding-function-arguments-to-add_action/#post-692075)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
