Redirect to settings page after install

I can’t find any info on this anywhere but i’m sure iv’e seen it done before.

I would like to have a user taken to the settings page for my plugin after install, so either auto-redirected or change the “back to plugins” link to a custom link.

Read More

Thanks in advance

SOLVED

function myplugin_activate() {    
    // TODO: Install your plugin here.

    // I don't know of any other redirect function, so this'll have to do.
    wp_redirect(admin_url('options-general.php?page=myplugin_settings'));exit;
    // You could use a header(sprintf('Location: %s', admin_url(...)); here instead too.
}
register_activation_hook(__FILE__, 'myplugin_activate');

@Zack – Your method works great however you forgot to exit after wp_redirect. (source http://codex.wordpress.org/Function_Reference/wp_redirect)

Many thanks

Related posts

Leave a Reply

3 comments

  1. Register an activation hook and then redirect the user’s browser when you’re done installing your plugin.

    function myplugin_activate() {    
        // TODO: Install your plugin here.
    
        // I don't know of any other redirect function, so this'll have to do.
        wp_redirect(admin_url('options-general.php?page=myplugin_settings'));
        // You could use a header(sprintf('Location: %s', admin_url(...)); here instead too.
    }
    register_activation_hook(__FILE__, 'myplugin_activate');
    
  2. I see the question is already answered. But there is a alternate scenario where you might want to redirect to settings page after a theme installed. You can do it very easily using following codes 🙂

    if (is_admin() && isset($_GET['activated'])){
    
        wp_redirect(admin_url("themes.php?page=ot-theme-options"));
    }
    

    You just have to replace the following code themes.php?page=ot-theme-options
    With your own setting page url.

    It is farly easy to do and we are using WP redirect function.

    Thanks
    Sabbir

  3. Well, you also can use another and more elegant solution:

    register_activation_hook(__FILE__, function () {
        add_option('your_plugin_do_activation_redirect', true);
    });
    
    add_action('admin_init', function () {
        if (get_option('your_plugin_do_activation_redirect', false)) {
            delete_option('your_plugin_do_activation_redirect');
            if(wp_safe_redirect("options-general.php?page=myplugin_settings")) exit();
        }
    });
    

    Approved answer is old and produce error inside activation or redirect you to 404 page inside admin. This solution provide you safe redirection with no errors.