I would like to call a function when a I save a setting/option in a custom admin page.

  • 1
    Can you update your question with more details, such as which setting you're referring to, how you're adding it, etc
    – Tom J Nowell
    Jun 20, 2017 at 7:02

3 Answers 3


Every function hooked to admin_init will be called after you save settings in the admin page. You should add some extra check of conditions to trigger your code on correct page. For example:

is this the setting page? is set $_REQUEST with values from options page etc...

  • You're right. When save settings the function hooked is called. Thanks a lot !! Jun 20, 2017 at 8:33

When save settings the function hooked is called. The solution is check in this function this:

// check if the user have submitted the settings
 // wordpress will add the "settings-updated" $_GET parameter to the url
 if ( isset( $_GET['settings-updated'] ) ) {
   // add the function called

Hook into save_post ( https://developer.wordpress.org/reference/hooks/save_post/ ).

Within your function, to see if you're working with the option page you want, use get_current_screen() ( https://developer.wordpress.org/reference/functions/get_current_screen/ ).

You can then look through the $_POST/$_GET variables you're receiving.

Don't forget to use a nonce and filter the incoming values! ☝

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.