I already consulted this post and this post but did not see a solution.
I need to redirect a page based on its $post->post_type
and from what little I know, I can get this information inside the template_redirect
hook.
So I have code below inside functions.php
(of astra-child theme):
add_action('template_redirect', 'redir_sorteio');
function redir_sorteio() {
global $post;
if ($post->post_type == 'sorteio')
wp_redirect('/edicao/?id=' . $post->ID);
}
And it works perfectly.
But for some reason, errors have appeared within the log, like:
[18-May-2018 01:11:22 UTC] PHP Warning: Cannot modify header information - headers already sent by (output started at /home/rogeriod/public_html/wordpress/sortemania/wp-content/themes/astra-child/functions.php:32) in /home/rogeriod/public_html/wordpress/sortemania/wp-includes/functions.php on line 1311
Where line 32 of functions.php (above) is the wp_redirect('/edicao/?id=' . $post->ID)
and line 1311 of wordpress functions.php is the header
command inside do_robots
function:
function do_robots() {
header( 'Content-Type: text/plain; charset=utf-8' );
How can I find out what causes this and resolve it, since wp_redirect
is working and no error appears directly to the user?
exit;
afterwp_redirect()
. See the note in the Description section in the documentation. (This is true whether you usewp_redirect()
orwp_safe_redirect()
.)