Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WP_redirect not working (header already sent in pluggable.php) [duplicate]

I want to use this code in a template file:

if ( wp_is_mobile() ) {
wp_redirect( "/shop-mobile", $status );
}

but it says: header already sent by /filewithcode in .../wp_includes/pluggable.php on line 1196

I tried to clean the pluggable document from spaces.. what else could be the issue here? Thank you

like image 540
Marc Ster Avatar asked Oct 19 '25 09:10

Marc Ster


1 Answers

"To fix the "headers already sent" issue, you need to move all of your form processing from the bottom of the page to the top of the page. If you need to call wp_redirect() you must make that call before you print anything - HTML or anything else - to the page."

reference: https://wordpress.stackexchange.com/questions/81566/wp-redirect-headers-already-sent-after-front-end-submission-form

you can read this for more explanation of this problem

How to fix "Headers already sent" error in PHP

like image 178
evexoio Avatar answered Oct 21 '25 23:10

evexoio



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!