Forums

wp_redirect in mu-plugin must die()...? (1 post)

  1. orensol
    Member
    Posted 3 years ago #

    Hi,

    I am using a plugin (mu-plugin) to perform a wp_redirect, and it doesn't redirect as expected. It seems that somewhere along the way the status_header gets overwritten, because if I die() after wp_redirect, the redirect performs well.

    Working code:

    function my_plugin_redirect($id)
    {
    $permalink = get_permalink($id);
    wp_redirect($permalink,301);
    die();
    }
    add_action('parse_request','my_plugin_redirect');

    Non-working code:

    function my_plugin_redirect($id)
    {
    $permalink = get_permalink($id);
    wp_redirect($permalink,301);
    }
    add_action('parse_request','my_plugin_redirect');

    Is it because i'm hooking it to parse_request? Is that too early?

    And sorry for the title pun, I just had to.

    Oren

Topic Closed

This topic has been closed to new replies.

About this Topic