Surfe.be - passive income

Wordpress : Redirect User after Activating Theme

Redirect User after Activating Theme

This tutorial we are going to learn how to redirect user after activating a wordpress theme. This is little bit tricky but easy. So let's start our tutorial . 

For doing that , open your theme functions.php file and paste the following code.


/* Redirect on theme activation */
add_action('admin_init', function(){
    global $pagenow;
    if ("themes.php" == $pagenow && is_admin() && isset($_GET['activated'])) {
        wp_redirect(esc_url_raw(add_query_arg('page', 'keenshot', admin_url('options-general.php'))));
    }
});

Now see , we call a action admin_init and we redirected user to keenshot page. In admin_url('options-general.php') section you can use themes.php also. if you use themes.php then the keenshot page will be included into appereance section otherwise settings section.

Now we have to create our custom keenshot page to redirect the user after activating the theme to this following page.  now paste thisbelow code to your fanctions.php file.

function keenshot_register_settings()
{
    add_option('keenshot_option_name', 'This is my option value.');
    register_setting('keenshot_options_group', 'keenshot_option_name', 'keenshot_callback');
}
add_action('admin_init', 'keenshot_register_settings');
function keenshot_register_options_page()
{
    add_options_page('Page Title', 'Keenshot', 'manage_options', 'keenshot', 'keenshot_options_page');
}
add_action('admin_menu', 'keenshot_register_options_page');
function keenshot_options_page()
{
?>
    <div>       
        <h2>Hey dude!</h2>
    </div>
<?php
}

This code for our admin menu. Now customize keenshot_options_page() function according to your requirement. Hope it will help you.

Leave a comments

LET'S SOCIALITE

Recent Tweets