This question already has an answer here:
I want my webpage to redirect to another webpage once some code is run by a user action. However, I am coding PHP on a Wordpress page (with php plugin) and I keep getting the error that the headers are already sent. Even if I try ob_start approach I still get this error. Does anyone know a workaround to redirecting after a user clicks a button on the webpage and a query is run considering that the headers have already been sent by the wordpress code?
The error message isWarning: Cannot modify header information – headers already sent by (output started at...
//the code currently
header("Location: http://example.com/full/?wid=$the_WID");
</div>
PHP header() function must be called before send ANY type of data (except another headers) at browser and ob_start too if you wish to capture ALL trafic sent to client browser!!
Have you tried to write a javascript that makes the redirection?
<script type="text/javascript">
window.location.href = "http://example.com/full/?wid=<?= $the_WID ?>";
</script>
Possibly Wordpress API let you do that, but I don't know how works that API.
Good luck!