0

Warning Message :

Warning:Cannot modify header information-headers already sent by (output started at (/themes/kaboodle/functions/admin-setup.php:174) in /wp-includes/pluggable.php on line 940

There is seems to an warning in line number 174 of file admin-setup.php which is written as below :

echo '<link href="'. get_template_directory_uri() . '/styles/'. $style . '.css" rel="stylesheet" type="text/css" />' . "\n\n";

i have checked the admin-setup file with any hidden whitespace on php quotes() but still error is persisting. Could anyone help me out to solve this warning message. for reference i am putting lines below those are required to check for such error.

Line 174 :

*echo '<link href="'. get_template_directory_uri() . '/styles/'. $style . '.css" rel="stylesheet" type="text/css" />' . "\n\n";*

Re-direct function written as:

function woo_themeoptions_redirect () {
    // Do redirect
    header('Location: ' . admin_url() . 'admin.php?page=woothemes');
} // End woo_themeoptions_redirect()
vishuB
  • 4,173
  • 5
  • 31
  • 49
  • **Need to Know if i can resolve by changing the statement written with Echo**. i tried to refer print/echo part of below link *http://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in-php* but unable to solve the same in my cache – user3655188 Sep 04 '15 at 12:16
  • 1
    you can't use `header` function after outputting => echoing something – Michael Kunst Sep 04 '15 at 12:18
  • Are you trying to include CSS links, then redirect the page? If so, why? But anyway, you can echo a meta redirect instead of using header. – Popnoodles Sep 04 '15 at 12:29

3 Answers3

1

First, you should use wp_enqueue_style to add styles, like so

function my_styles_function() 
{
    wp_enqueue_style( 'my-style-name', get_template_directory_uri() . 'somestyle.css");
}

add_action( 'wp_enqueue_scripts', 'my_styles_function' );

Second, redirects should be done with wp_safe_redirect on admin_init or init to ensure there is no output before redirect is supposed to happen. For example

function my_redirect()
{
       wp_safe_redirect('link_here');
}

add_action('admin_init', 'my_redirect'); // for admin
add_action('init', 'my_redirect'); // for frontend

Also, what is the point of echoing style before redirecting?

Igor Yavych
  • 4,166
  • 3
  • 21
  • 42
0

yes you can solve it the mistakes to that error are

1.spaces before

<?php ?>

2.html contents before header

3.anything echoed before header

you have to remove those

but even after that it show you the same error you can use javascript redirect like this

<script type="text/javascript">
  window.location.assign('your desired location');
</script>
Syed mohamed aladeen
  • 6,507
  • 4
  • 32
  • 59
0
 header('Location: ' . admin_url() . 'admin.php?page=woothemes');

you can not use that, after you echoed anything. The echo sends the header (as most servers send their output in pieces) and therfore you can't modify it anymore with a header() command.

Popnoodles
  • 28,090
  • 2
  • 45
  • 53
DocRattie
  • 1,392
  • 2
  • 13
  • 27