Home › Forums › Front-end Issues › ACF plugin is causing "headers already send by…" error
ACF plugin is causing “cannot modify header information – headers already send by (bla bla bla/public_html/wp-content/themes/bifrost/header.php:1)” in my file.
The firsts 26 lines of my header.php:1 file show:
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<meta charset=”<?php bloginfo(‘charset’); ?>”>
<meta name=”viewport” content=”width=device-width, initial-scale=1″>
<meta http-equiv=”X-UA-Compatible” content=”ie=edge”>
<?php
/**
* Queried Object
*
* In case it is shop page get_queried_object won’t
* work, it needs to be changed to a custom WooCommerce
* function wc_get_page_id.
*/
$bifrost_queried_object = class_exists(‘WooCommerce’) && is_shop() ? wc_get_page_id(‘shop’) : get_queried_object();
/**
* Redirect
*/
if (get_field(‘general_redirect’, $bifrost_queried_object) && get_field(‘general_redirect_url’, $bifrost_queried_object)) {
wp_redirect(get_field(‘general_redirect_url’, $bifrost_queried_object));
exit;
}
wp_head();
?>
I already:
1 – checked for blank spaces
2 – moved the <!DOCTYPE html> around
3 – Installed an older version of ACF
4 – and did a lot of other things suggested in previous post, but nothing worked so far.
When I deactivate ACF plugin, my page work fine, but I loose all configuration made using the ACF plugin. Somehow, this same configuration is working fine in bermelloajamil.info, but after migrating this content to bermelloajamil.com, the error shows up. Can you guys help me?
The problem is here
/**
* Redirect
*/
if (get_field(‘general_redirect’, $bifrost_queried_object) && get_field(‘general_redirect_url’, $bifrost_queried_object)) {
wp_redirect(get_field(‘general_redirect_url’, $bifrost_queried_object));
exit;
}
You are attempting to redirect after HTML output has been started. This code needs to happen before
<!DOCTYPE html>
Thanks for your help. I fixed the code as you suggested, but the same error shows:
Warning: Cannot modify header information – headers already sent by (output started at /home/customer/www/bermelloajamil.com/public_html/wp-content/themes/bifrost/header.php:1) in /home/customer/www/bermelloajamil.com/public_html/wp-includes/pluggable.php on line 1421
Here is a snippet of the fixed code:
<?php
if (get_field(‘general_redirect’, $bifrost_queried_object) && get_field(‘general_redirect_url’, $bifrost_queried_object)) {
wp_redirect(get_field(‘general_redirect_url’, $bifrost_queried_object));
exit;
}
?>
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<meta charset=”<?php bloginfo(‘charset’); ?>”>
<meta name=”viewport” content=”width=device-width, initial-scale=1″>
<meta http-equiv=”X-UA-Compatible” content=”ie=edge”>
<?php
/**
* Queried Object
*
* In case it is shop page get_queried_object won’t
* work, it needs to be changed to a custom WooCommerce
* function wc_get_page_id.
*/
$bifrost_queried_object = class_exists(‘WooCommerce’) && is_shop() ? wc_get_page_id(‘shop’) : get_queried_object();
wp_head();
?>
</head>
Thanks so much for your help!
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.