• Matt

    (@mattcheahgmailcom)


    Hey all,
    I have a website that has a WordPress blog and shows a widget list of recent posts on the main site outside of the blog, using require(...../wp-blog-header.php); and get_posts();

    I’ve been getting a lot of “Cannot modify header information – headers already sent by (output started at ..” PHP error messages, on the pages where we’re loading this list of recent posts. I guess WordPress is editing HTTP headers, which might make sense in the main instance but since output has already begun before we get to the recent posts widget, it doesn’t make sense at all.

    I’d like to turn on output_buffering to deal with this issue, but whenever I turn it on, the pages with the widget show a 404 (but render perfectly normally). I’m not sure what the cause is, but I’m sure all of this has to do with WordPress sending headers when it doesn’t need to. Is there any way to disable this behavior when I’m outside of the main WP instance?

    Thanks!

Viewing 9 replies - 1 through 9 (of 9 total)
  • Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    >> “Cannot modify header information – headers already sent by <<

    This is usually indicative of characters before the opening <?php of a file or soemthing added after the last ?>. If it’s come on suddenly, it may be that your site has been hacked.

    That’s where you should be focusing your attention first.

    Do you have WordFence installed or another good security plugin that can scan your site for files that don’t match their versions in the repository?

    Thread Starter Matt

    (@mattcheahgmailcom)

    Hi Steve, thanks for your response.
    There most certainly are characters before the opening <?php, as this widget is loaded in the footer of my website template, so it’s not a hacking issue. I suppose I could create the wordpress instance in the header of my website prior to any output, but I feel as if there should be a better solution for anyone who wants to query WordPress further down the page.

    Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    I think you’re misunderstanding me. I’m specifically referring to things like functions.php.

    If this used to work and does not not, then use WordFence to scan all your files.

    Thread Starter Matt

    (@mattcheahgmailcom)

    I see, no I believe I have always gotten these messages. Thanks!

    Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    OK, then you need to track down the bad code.

    Enable wp_debug and wp_debug_log and after an error, look at wp-content/debug.log to see if anything gets logged there. https://codex.www.ads-software.com/Debugging_in_WordPress

    Thread Starter Matt

    (@mattcheahgmailcom)

    Thanks Steve. I don’t think there’s any bad code – I’m assuming everything is working as it is supposed to. I’m just asking if there’s any way to disable WP sending headers when it doesn’t need to.

    Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    There’s a bug in the code of your theme or a plugin.

    Thread Starter Matt

    (@mattcheahgmailcom)

    So… may I ask why? How do you know there is a bug? What does it sound like doesn’t work properly to you?

    BTW there are no error messages except notices which I have corrected, and disabling plugins has no effect on HTTP headers being sent.

    Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    Because you should not be getting that warning. Since it doesn’t bother you and your site appears to work, you can ignore it.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘How to not send HTTP headers when querying WP outside of the main instanc’ is closed to new replies.