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
“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
Ensure that the code above the wp_redirect function have not already sent the header information to the server.
Header information will be sent to the server in some of the following scenarios:
print, echo
Space before
<?php or space after ?>
Check if the headers are being already sent using:
Refer the below link for further guidance.How to fix “Headers already sent” error in PHP