Cannot modify header information - headers already sent

In my error log I am getting a lot of "headers already sent" messages.
PHP Warning: Cannot modify header information - headers already sent in /plugins/simple-membership/classes/class.swpm-init-time-tasks.php on line 20

PHP Warning: Cannot modify header information - headers already sent in /plugins/wpfront-notification-bar/classes/class-wpfront-notification-bar.php on line 68

PHP Warning: Cannot modify header information - headers already sent in /plugins/wordfence/lib/wfLog.php on line 1174

PHP Warning: Cannot modify header information - headers already sent in /plugins/wordfence/lib/wfUtils.php on line 1097

How do I deal with these warnings please.
Support access is granted.

  • Nithin

    Hi Mary,

    Hope you are doing good today. :slight_smile:

    Headers already sent notice, always relate to files having new lines, spaces etc most probably in the beginning, or ending of PHP tags.

    If you are sure that you haven't made any changes to the plugin files, then it's mostly related to having new lines, spaces etc in your wp-config.php file, located in your root folder. Would recommend you to check your wp-config.php for any difference, by following the troubleshooting steps mentioned in this link:
    https://codex.wordpress.org/FAQ_Troubleshooting#How_do_I_solve_the_Headers_already_sent_warning_problem.3F

    Please let us know how that goes, and let us know if you still need any further assistance. Have a nice day. :slight_smile:

    Kind Regards,
    Nithin

  • Mary

    I'm getting the errors again and I did some reading of the link you mentioned. It says:

    Wrong:
    <?php
    some code;
    ?>

    <?php
    some other codes;
    ?>
    Correct:
    <?php
    code;

    some other code;
    ?>

    When I look at my wp-login.php file it is filled with <?php's and ?>'s, specifically at line 71 where it says:

    <?php

    wp_enqueue_style( 'login' );

    /*
    * Remove all stored post data on logging out.
    * This could be added by add_action('login_head'...) like wp_shake_js(),
    * but maybe better if it's not removable by plugins
    */
    if ( 'loggedout' == $wp_error->get_error_code() ) {
    ?>

    This is one of my errors. Should I remove all of the <?php's and ?>'s except at the beginning and end as shown?

  • Ash

    Hello Mary

    When you see Header already sent message, then you are sure that something is being printed earlier. Now, if you look at the error, you can know that from which file those are being printed. Like:

    /plugins/simple-membership/classes/class.swpm-init-time-tasks.php on line 20
    /plugins/wpfront-notification-bar/classes/class-wpfront-notification-bar.php on line 68
    etc....

    Also, this error doesn't always relate to space, new line etc but so many things. For example, you have a redirect script in php and from one of your file a simple notice is generated. Then the redirect won't work and you would see a "header already sent in that file on line xxx" message.

    <?php
    some code;
    ?>

    <?php
    some other codes;
    ?>

    This can be right too. Sometimes, you may need to put html inside php block. You can put html as many times as you want inside a single php block, like:

    <?php
    //function abc starts
    // This is php code
    // This is php code
    ?>
    Here comes some html
    Here comes some more html
    <?php
    // This is php code
    // This is php code
    // Function abc ends here
    ?>

    But we say, best practice is not to put closing php tags, like:

    <?php
    //function abc starts
    // This is php code
    // This is php code
    ?>
    Here comes some html
    Here comes some more html
    <?php
    // This is php code
    // This is php code
    // Function abc ends here
    // I am not closing php tags

    If your file contains php code at the very last line, then you don't need to close.

    When I look at my wp-login.php file it is filled with <?php's and ?>'s, specifically at line 71 where it says:

    <?php

    wp_enqueue_style( 'login' );

    /*
    * Remove all stored post data on logging out.
    * This could be added by add_action('login_head'...) like wp_shake_js(),
    * but maybe better if it's not removable by plugins
    */
    if ( 'loggedout' == $wp_error->get_error_code() ) {
    ?>

    You don't need to worry about wordpress core files like wp-login.php, if they do any mistake in those files, they will fix it ASAP :slight_smile:

    Hope it helps :slight_smile: Please feel free to ask more question if you have any.

    Cheers
    Ash

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.