Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use the settings API to Redirect to correct options page after save in Wordpress

I'm trying to create a new admin page in wordpress for some settings. Ideally, I'd like it to be a top-level menu page, but I'd settle for it being a sub-menu under settings. I've followed all the docs, and I have a page that shows up, and the settings are saved. However, I can't get Wordpress to redirect back to the correct page after hitting save.

I finally simply copied and pasted the code from the Codex into my functions.php: http://codex.wordpress.org/Creating_Options_Pages

And I still have the same problem.

The first example redirects to admin.php, which causes a plain white screen while the second example redirects to the main settings page instead of the custom settings sub-page.

Surely there has to be a way to tell Wordpress to redirect to your custom page after saving.

Thanks in advance.

like image 629
jhummel Avatar asked Nov 02 '22 01:11

jhummel


1 Answers

The triggering factor for this might be the form's action attribute.

Depending on how you save your settings, you probably want to have your action point to options.php most of the time.

Other than that, settings_field() is also important in your form. It'll add several hidden input fields to identify the form.

Using this code as an example works perfectly for me at least on WP 3.9.

like image 77
josephting Avatar answered Nov 10 '22 07:11

josephting