Title: Custom function from plugin
Last modified: July 26, 2017

---

# Custom function from plugin

 *  Resolved [44nato44](https://wordpress.org/support/users/44nato44/)
 * (@44nato44)
 * [8 years, 10 months ago](https://wordpress.org/support/topic/custom-function-from-plugin/)
 * Hi,
 * I am trying to get heads and tail, of what is the best way.
 * In my multi site installation, I have made a site where I have made my own custom
   functions.
 * I understand that I can make a child theme and use my function there.
 * But I would like to create a plugin, so I can add my plugin to other sites and
   reuse my custom functions.
 * My site does not seem to work, when I move the function file from the folder 
   mu-plugins (where my functions work) folder to my plugin folder where my site
   will not load probably, only the header is loading.
 * Is it because I need to use the add_action commands to load the functions ?
 * I have not been able to find a site which explains it so I understand it, unfortunately.
 * Hope somebody can help.
 * Thanks
 * Best Regards
 * Torben

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

 *  [catacaustic](https://wordpress.org/support/users/catacaustic/)
 * (@catacaustic)
 * [8 years, 10 months ago](https://wordpress.org/support/topic/custom-function-from-plugin/#post-9355338)
 * What errors are you getting when the site breaks? You may need to enable WP_DEBUG
   in your wp-contig.php file temporarily to see the error messages.
 *  Thread Starter [44nato44](https://wordpress.org/support/users/44nato44/)
 * (@44nato44)
 * [8 years, 10 months ago](https://wordpress.org/support/topic/custom-function-from-plugin/#post-9356492)
 * I get this error – Fatal error: Call to undefined function wpse_58429() in /var/
   www/html/wp-content/themes/viking/header.php on line 58
 * Where wpse_58429() is a function in my function file which is called in the header
 * Any ideas how I can call the function from my plugin ?
 * I tried to do this –
 * add_action( ‘call_wpse_58429’, ‘wpse_58429’ );
 * $current_user = do_action(‘wpse_58429’);
 * But then I get this error – Warning: call_user_func_array() expects parameter
   1 to be a valid callback, function ‘wpse_58429’ not found or invalid function
   name in /var/www/html/wp-includes/class-wp-hook.php on line 298
 * I tried then the following –
 * //add_action( ‘call_wpse_58429’, ‘wpse_58429’ );
 * $current_user = call_user_func(‘wpse_58429’);
 * Where I get this error –
 * Warning: call_user_func() expects parameter 1 to be a valid callback, function‘
   wpse_58429’ not found or invalid function name in /var/www/html/wp-content/themes/
   viking/header.php on line 73
 * So all in all I am not sure the function gets into my theme from the plugin.
 * Appreciate any help I can get
 *  [catacaustic](https://wordpress.org/support/users/catacaustic/)
 * (@catacaustic)
 * [8 years, 10 months ago](https://wordpress.org/support/topic/custom-function-from-plugin/#post-9356715)
 * It looks like you’re trying to use the function before it’s loaded. Plugins load
   before themes do, so if you’re trying to do that as soon as your plugin loads,
   the themes functions won’t be available yet.
 * The way to do it is to use the after_setup_theme action, as that is fired after
   the theme is loaded.
 * function my_function( ){
    $current_user = wpse_58429(); }
 * add_action( ‘after_setup_theme’, ‘my_function’ );`
 * If that doesn’t work, go back to your themes author and ask for support. They’ll
   be able to help you more.
 *  Thread Starter [44nato44](https://wordpress.org/support/users/44nato44/)
 * (@44nato44)
 * [8 years, 10 months ago](https://wordpress.org/support/topic/custom-function-from-plugin/#post-9372549)
 * Thanks, I will contact the theme author
 *  Thread Starter [44nato44](https://wordpress.org/support/users/44nato44/)
 * (@44nato44)
 * [8 years, 10 months ago](https://wordpress.org/support/topic/custom-function-from-plugin/#post-9372552)
 * Resolved

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

The topic ‘Custom function from plugin’ is closed to new replies.

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 5 replies
 * 2 participants
 * Last reply from: [44nato44](https://wordpress.org/support/users/44nato44/)
 * Last activity: [8 years, 10 months ago](https://wordpress.org/support/topic/custom-function-from-plugin/#post-9372552)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
