I'm encountering this error. and I have no idea dealing with this.
Cannot modify header information - headers already sent by (output started at /home/ben213/public_html/wp-content/themes/Bendaggers/functions.php:9) in /home/ben213/public_html/wp-includes/pluggable.php on line 934
my Functions.php file line # 9 is:
<?php if(function_exists('register_sidebar'))register_sidebar();?>
while my pluggable.php # 934 is
function wp_redirect($location, $status = 302) { global $is_IIS; $location = apply_filters('wp_redirect', $location, $status); $status = apply_filters('wp_redirect_status', $status, $location); if ( !$location ) // allows the wp_redirect filter to cancel a redirect return false; $location = wp_sanitize_redirect($location); if ( !$is_IIS && php_sapi_name() != 'cgi-fcgi' ) status_header($status); // This causes problems on IIS and some FastCGI setups header("Location: $location", true, $status);} endif;
I'm having a hard time figuring this out since im not a programmer. what seems to be wrong? kindly help me please...
The first thing you need to do when you run into the “Cannot modify header information – headers already sent by” error is to open the file that's causing the problem. Then, locate the line the message indicates. In this scenario, you can reach the source of the problem using the WordPress theme editor.
If an HTML element is placed before a header call, it can cause the “Cannot Modify Header Information – Headers Already Sent By” error. To fix the error, place the HTML block after the header statement.
However, if you get an error "Headers already sent" as the first error and it tells you the error is near the end of a file (check which file "output started at" points to), that probably means that there are extra spaces or lines after a closing ?> php tag.
This error message gets triggered when anything is sent before you send HTTP headers (with setcookie or header ). Common reasons for outputting something before the HTTP headers are: Accidental whitespace, often at the beginning or end of files, like this: <?
Here’s how to troubleshoot WordPress “ Cannot modify header information” message: 1. Editing Corrupted Files If the faulty file has whitespaces, the easiest way to solve the issue is to manually edit the issue via an FTP or a File Manager.
You can review and scan the .php file that’s specified in the warning message and fix the code. When you first see the “Cannot Modify Header Information – Headers Already Sent By” error and the warning message tells you that the broken file is located in the WordPress core file there’s a simple solution to that.
If you try and change WordPress headers or redirect after this “gap”, you’ll get the “headers already sent” message. Often you will code your PHP files in an editor like Notepad++.
By default, the header must be called first before sending any output from the body. Sending output before calling the header, including having unparsed HTML sections in the PHP file, likely causes the error. Here’s what an incorrect code will look like: To solve this issue, you need to find the statements that send output above the header.
Your theme is printing output (text) to the browser, but then for some reason WordPress is redirecting the user (with wp_redirect) away from that page before the whole page is rendered. You can't start printing output and then redirect, or you'll get the error you see. That's what Paul Grime was getting at in his comment.
Ken White commented with a reference to a post with a similar problem. I've fixed this in my own experience by buffering the output of the script.
In your theme's functions.php
file (which gets included every time your theme's pages load), put the following:
//allow redirection, even if my theme starts to send output to the browser add_action('init', 'do_output_buffer'); function do_output_buffer() { ob_start(); }
Now, even if part of your theme starts to send input to the browser, PHP won't send that text until the page is fully loaded, which allows WordPress to redirect users, if necessary, as part of its own logic.
If you are trying to redirect to another page from your current page, where you have impose a condition or without condition, then use this code. E.gs you have two pages A.php, & B.php and currenty you are in A.php where you want to go to other page B.php on clicking the BUTTON.
if(isset($_POST['save_btn'])) { //write some of your code here, if necessary echo'<script> window.location="B.php"; </script> '; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With