I have create a plugin that I want to redirect to the options page of that plugin after the user activates it. This works fine when I test it locally. However, on a live installation of wordpress, it does not behave in the same manner.

Here is my code below:

        register_activation_hook(__FILE__, 'srpt_plugin_activate');
add_action('admin_init', 'srpt_plugin_redirect');

function my_plugin_activate() {
    add_option('srpt_activation_redirect', true);

function srpt_plugin_redirect() {
    $srpt_url = admin_url( 'admin.php?page=plugin-options-page/plugin-options-page.php', 'http' );
    if (get_option('srpt_activation_redirect', false)) {

This is the substitution to the original uri:


Thank you for your time if I don't get a chance to thank you later. Wayne Hatter.

  • Okay, I just tested it again with this addition: wp-admin/admin.php?page=plugin-options-page/plugin-options-page.php Then I got this message: The plugin generated 245 characters of unexpected output during activation. If you notice “headers already sent” messages, problems with syndication feeds or other issues, try deactivating or removing this plugin. May 28 '12 at 12:28
  • If there is any output before the redirection function, it will fail because headers can't be set after the output has been started. Turn WP_DEBUG on in wp-config.php file and test.
    – Ashfame
    May 28 '12 at 12:49

You add this as your activation hook:

    register_activation_hook(__FILE__, 'srpt_plugin_activate');

but the function is my_plugin_activate not srpt_plugin_activate. This is based on the fact that there is no function srpt_plugin_activate, and looking at the code my_plugin_activate fills its place in the flow. Is this a typo in the question or in the live code?

Plus, re your 245 characters of unexpected output. You are creating no output intentionally before the redirect? So you must be getting an error message, possibly PHP warning or notice level, and that is giving you the 245 characters of unexpected output. I do not know why your options page url would end in .php my plugins always create their options pages using add_submenu_page and I define a string to use as the page name, and then the url for the page is for example: /wp-admin/admin.php?page=the_string_i_gave. Here is an example of me adding an options page to one of my plugins:

add_submenu_page('wswpsubscriber', __('Main Management Area','WsWpSubscriber'), __('Options','WsPsSubscriber'),'manage_options','wswps_setup',array(&$this,'subscribe_main_menu'));

function subscribe_main_menu

then controls the output for the page found at /wp-admin/admin.php?page=wswps_setup

  • Thanks a lot man, it was a typo. I used an example script and forgot to change that function name to reflect the changes. Thanks alot. I will buy you some pencils one day. May 28 '12 at 14:40
  • 1
    An upvote and a mark as correct will do fine May 28 '12 at 20:59
  • I need a reputation score of 15. I only have a reputation of 1. Obviously I am new to this exchange. So please have patience with me. May 29 '12 at 13:30
  • Oh, I was only kidding Wayne, but I didn't think you needed 15 points to mark an answer to your own question as correct using the tick under the score. May 30 '12 at 20:41

Hello i have used bellows code redirect after plugin activation. You can use this code. It's working nicely.

register_activation_hook(__FILE__, 'nht_plugin_activate');
add_action('admin_init', 'nht_plugin_redirect');

function nht_plugin_activate() {
add_option('nht_plugin_do_activation_redirect', true);

function nht_plugin_redirect() {
if (get_option('nht_plugin_do_activation_redirect', false)) {

"nht_" is my plugin prefix & "edit.php?post_type=headline&page=news-headline" is redirect page. please replace this those. You can see more tutorial on http://www.e2soft.com

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.