WordPress Plugin Redirect After Activation

Today, We want to share with you WordPress Plugin Redirect After Activation.In this post we will show you Redirect to a welcome page after updating plugin, hear for Refresh or redirect page after activate my plugin we will give you demo and example for implement.In this post, we will learn about plugin activation and deactivation hook in wordpress with an example.

WordPress Plugin Redirect After Activation

There are the Following The simple About WordPress Plugin Redirect After Activation Full Information With Example and source code.

Read Also:  jQuery ajax pagination in php MySQLi

As I will cover this Post with live Working example to develop Redirect to settings page after install, so the How to Redirect On Theme Activation for this example is following below.

Method : 1

How to redirect to settings page once the plugin is activated?

function your_plugin_prefix_activation_redirect( $plugin ) {
    if( $plugin == plugin_basename( __FILE__ ) ) {
        exit( wp_redirect( admin_url( 'options-general.php' ) ) );
    }
}
add_action( 'activated_plugin', 'your_plugin_prefix_activation_redirect' );

Method : 2 Redirect after plugin activation

register_activation_hook(__FILE__, 'ntbr_plugin_activate');
add_action('admin_init', 'ntbr_plugin_redirect');

function ntbr_plugin_activate() {
    add_option('ntbr_do_activation_redirect', true);
}

function ntbr_plugin_redirect() {
    if (get_option('ntbr_do_activation_redirect', false)) {
        delete_option('ntbr_do_activation_redirect');
        wp_redirect(MY_PLUGIN_SETTINGS_URL);
    }
}

Method : 3 Redirect to settings page after install

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');

How to redirect to theme settings page after activation

use for WordPress Themes (code and paste it into functions.php)

global $plugincheck;
if ( isset( $_GET['current'] ) && $plugincheck == 'themes.php' ) {
    wp_redirect( admin_url( 'themes.php?page=theme-settings-slug' ) );
    exit;
}

use for WordPress plugin

global $plugincheck;
if ( isset( $_GET['current'] ) && $plugincheck == 'plugins.php' ) {
    wp_redirect( admin_url( 'options-general.php?page=your-custom-plugin-page-slug' ) );
    exit;
}

Web Programming Tutorials Example with Demo

Read :

Read Also:  jQuery Multiple Email Address Validation in one text box

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about WordPress Plugin Redirect After Activation.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.