How to redirect to theme settings page after activation

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.

🔥 HOT: Interested in boosting your WordPress SEO? My Slim SEO plugin is a super lighweight and automated plugin that handles most the hard work for you: meta tags, sitemap, redirection, schema & link building.

👉 Have a look and you will love it: wpslimseo.com

Leave a Reply

Your email address will not be published. Required fields are marked *


Copyright © 2024 Deluxe Blog Tips. All rights reserved.

My products: Meta Box | Slim SEO