Skip to main content
add code formatting and improve readability
Source Link

Here's a one line solution.

Put this in your functions.phpfunctions.php file:

add_action('template_redirect', 
                  function(){
                      ob_start();
                      }
    );
add_action( 'template_redirect', function () {
    ob_start();
} );

ob_start()ob_start() begins output buffering, when the template_redirecttemplate_redirect actions are completed, and nothing has been sent to the browser. That means wp_redirect()wp_redirect() works from anywhere:

wp_redirect($url);
exit;
wp_redirect( $url );
exit;

including in a shortcode. If the script terminates normally, without an exit, the buffer is automatically flushed and the whole page is sent at that time.

Cheeky ... but it seems to work for me.

Here's a one line solution.

Put this in your functions.php file:

add_action('template_redirect', 
                  function(){
                      ob_start();
                      }
    );

ob_start() begins output buffering, when the template_redirect actions are completed, and nothing has been sent to the browser. That means wp_redirect() works from anywhere:

wp_redirect($url);
exit;

including in a shortcode. If the script terminates normally, without an exit, the buffer is automatically flushed and the whole page is sent at that time.

Cheeky ... but it seems to work for me.

Here's a one line solution.

Put this in your functions.php file:

add_action( 'template_redirect', function () {
    ob_start();
} );

ob_start() begins output buffering, when the template_redirect actions are completed, and nothing has been sent to the browser. That means wp_redirect() works from anywhere:

wp_redirect( $url );
exit;

including in a shortcode. If the script terminates normally, without an exit, the buffer is automatically flushed and the whole page is sent at that time.

Cheeky ... but it seems to work for me.

added 122 characters in body
Source Link

Here's a one line solution.

Put this in your functions.php file:

add_action('template_redirect', 
                  function(){
                      ob_start();
                      }
    );

ob_start() begins output buffering, sowhen the template_redirect actions are completed, and nothing ishas been sent to the browser. That means wp_redirect() works from anywhere,:

wp_redirect($url);
exit;

including in a shortcode. WhenIf the script terminates normally, without an exit, the buffer is automatically flushed and the whole page is sent at that time.

Cheeky ... but it seems to work for me!.

Here's a one line solution.

Put this in your functions.php file:

add_action('template_redirect', 
                  function(){
                      ob_start();
                      }
    );

ob_start() begins output buffering, so nothing is sent to the browser. That means wp_redirect() works from anywhere, including in a shortcode. When the script terminates, the buffer is automatically flushed and the whole page is sent at that time.

Cheeky ... but it seems to work for me!

Here's a one line solution.

Put this in your functions.php file:

add_action('template_redirect', 
                  function(){
                      ob_start();
                      }
    );

ob_start() begins output buffering, when the template_redirect actions are completed, and nothing has been sent to the browser. That means wp_redirect() works from anywhere:

wp_redirect($url);
exit;

including in a shortcode. If the script terminates normally, without an exit, the buffer is automatically flushed and the whole page is sent at that time.

Cheeky ... but it seems to work for me.

added 1 character in body
Source Link

Here's a one line solution.

Put this in your functionfunctions.php file:

add_action('template_redirect', 
                  function(){
                      ob_start();
                      }
    );

ob_start() begins output buffering, so nothing is sent to the browser. That means wp_redirect() works from anywhere, including in a shortcode. When the script terminates, the buffer is automatically flushed and the whole page is sent at that time.

Cheeky ... but it seems to work for me!

Here's a one line solution.

Put this in your function.php file:

add_action('template_redirect', 
                  function(){
                      ob_start();
                      }
    );

ob_start() begins output buffering, so nothing is sent to the browser. That means wp_redirect() works from anywhere, including in a shortcode. When the script terminates, the buffer is automatically flushed and the whole page is sent at that time.

Cheeky ... but it seems to work for me!

Here's a one line solution.

Put this in your functions.php file:

add_action('template_redirect', 
                  function(){
                      ob_start();
                      }
    );

ob_start() begins output buffering, so nothing is sent to the browser. That means wp_redirect() works from anywhere, including in a shortcode. When the script terminates, the buffer is automatically flushed and the whole page is sent at that time.

Cheeky ... but it seems to work for me!

Source Link
Loading