In some situations such as we have many menu items or we create theme settings page in another location than Appearance where it should belong to, users might be confused when they don't know where to find the theme settings page after activating theme. So it would be a good practice to redirect them directly to theme settings page immediately after activation and this post will show you how to do that.
All you need to do is copying this code and paste it into functions.php
file of your theme:
global $pagenow; if ( isset( $_GET['activated'] ) && $pagenow == 'themes.php' ) { wp_redirect( admin_url( 'themes.php?page=theme-settings-slug' ) ); exit; }
Remember to change theme-settings-slug
to your settings page slug.
You can also do the same thing for plugins with this code:
global $pagenow; if ( isset( $_GET['activated'] ) && $pagenow == 'plugins.php' ) { wp_redirect( admin_url( 'options-general.php?page=plugin-page-slug' ) ); exit; }
Beside plugin-page-slug
, you should change options-general.php
if you don't put the plugin page under Settings.
You also should wrap this code inside admin_init
hook to make sure it runs only in the backend.
Leave a Reply