0

I am using Ajax scroller on my new theme thats why i had to include some codes in my index page as well as wp-blog-header.php page. After few changes this is how my wp-blog-header pge looks like

if ( !isset($wp_did_header) ) {

$wp_did_header = true;

require_once( dirname(__FILE__) . '/wp-load.php' );

wp();
require_once( ABSPATH . WPINC . '/template-loader.php' );
header("HTTP/1.1 200 OK");}

this code was really helpfull and saved my time specially last line of the code ( header("HTTP/1.1 200 OK"); ). But when i use this code it gives error on footer side as:

Warning: Cannot modify header information - headers already sent by (output started at /home/xxxx/public_html/xxxx/blog/wp-content/plugins/all-in-one-seo-pack/aioseop.class.php:221) in /home/xxxx/public_html/xxxx/blog/wp-blog-header.php on line 11

also if i disable that plugin it gives this error :

 Warning: Cannot modify header information - headers already sent by (output started at /home/xxxx/public_html/xxx/blog/wp-content/themes/z/header.php:5) in /home/xxxx/public_html/xxxx/blog/wp-blog-header.php on line 11

When i remove it or change its line number error goes but theme doesnt work as expected.

And i am using this code in my theme to call that function

<?php require('/home/xxx/public_html/xxx/blog/wp-blog-header.php'); ?>

Is there any way to fix this issue? Thanks

Emre
  • 23
  • 1
  • 8
  • And what's on line 11 in `/home/xxxx/public_html/xxxx/blog/wp-blog-header.php`? – cheesemacfly Jan 11 '13 at 23:42
  • header("HTTP/1.1 200 OK"); – Emre Jan 11 '13 at 23:43
  • So it is already sending the same header you want, am I wrong? – cheesemacfly Jan 11 '13 at 23:45
  • But as i said to use Ajax functionality i am calling header twice in index page (read lots of articles about this and that was the only way). if i dont use that line 11 it gives 404 error and doesnt display anything – Emre Jan 11 '13 at 23:48
  • It makes no sense to hard code that call to `header` into `wp-blog-header.php`. WordPress will send that header on most page loads. You are always going to have trouble with "headers already sent" because are sending them and so is the Core. Additionally, it makes no sense that you would call the blog header twice in the same file. You are loading (or attempting to load) all of WordPress twice. That is nonsense. Someone is giving you bad information but there is not enough information in your post to tell you what to do instead. – s_ha_dum Jan 12 '13 at 01:14
  • Well i was really about the give up (you can see for how long i was trying to fix it). But fortunately i saw this answerhttp://wordpress.stackexchange.com/a/65490/18335 which is saying use wp-load instead of wp-blog-header. he made my day thanks to him :) – Emre Feb 02 '13 at 12:32
  • possible duplicate of [Headers already sent by PHP](http://stackoverflow.com/questions/8028957/headers-already-sent-by-php) – Jocelyn Mar 25 '13 at 02:00
  • [Also, you may check this](http://heera.it/headers-error-wordpress#.Ui-HF8ZmiSo). – The Alpha Sep 10 '13 at 20:55

3 Answers3

0

I had similar problem, all you need to do is to find in the first few lines of your function.php file and see if there is any commenting formatted as <!--your comment--> OUTSIDE of the <?php tag. It could cause the problem as I solved mine after remove the comment and move the comment at that begining of the function.php file into the <?php tag and use // instead.

I also heard extra space in the beginning of the function.php file could also cause problem

weia design
  • 1,250
  • 2
  • 14
  • 22
0

if you are doing a callback do it like this:

I was trying to redirect to Zoom Oauth Api and I achieved it like this

 if(!isset($_GET['callback'])) {
  include_once get_template_directory() . "/page-templates/meetings/index.php";

  $url = "https://zoom.us/oauth/authorize?response_type=code&client_id=" . CLIENT_ID . "&redirect_uri=" . REDIRECT_URI;
  
  wp_redirect($url);
  exit;
 }

rest of the code goes after the above code

Rashid Iqbal
  • 1,123
  • 13
  • 13
0

Although this was many years ago, i recently had the same issue.

To fix, (this varies) - Firstly make sure there is no direct output of tags within the functions.php file - As they are not needed unless outputting data directly.

Lastly, be sure your add_action or add_filter is ran correctly! Best to place this before the function starts.

JCrook
  • 411
  • 3
  • 7