Magento 2.2.5: Warning: Cannot modify header information - headers already sent by [custom_theme registration.php]
-
25-01-2021 - |
Question
I'm developing a custom theme and running into errors. The theme has been tested and working on various servers but, for some reason, since uploading to siteground I get the following error (file paths, vendor name etc. have been redacted and replaced with notes contained inside square brackets).
Warning: Cannot modify header information - headers already sent
"0":"Warning: Cannot modify header information - headers already sent by (output started at /[magento_root_directory]/app/design/frontend/[vendor]/[theme]/registration.php:1) in /[magento_root_directory]/vendor/magento/framework/Stdlib/Cookie/PhpCookieManager.php on line 148","1"
I've read that this is to do with whitespace before the <?php
tag, but there is no whitespace.
My registration.php
file is as follows (with vendor/theme name redacted):
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::THEME,
'frontend/[VendorName]/[themename]',
__DIR__
);
This is copied exactly from the file. The <?php
tag is on the first line and there is no whitespace following it.
The site is installed on a siteground shared hosting instance, though I don't think this should make a difference.
Does anyone know what the problem is?
There is a massive stacktrace following the error message, which I can share if this information is not enough.
When I visit the website homepage I see a blank page, with nothing logged in the console and the URL reads:
http://[my_website].com/pub/errors/report.php?id=[error_id]&skin=default
The page reloads, looping indefinitely and creating a new report each time with the same error message.
Update
My theme.xml
file is as follows:
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<theme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/theme.xsd">
<title>[ThemeTitle]</title>
<parent>Magento/blank</parent>
<media>
<preview_image>media/preview.jpg</preview_image>
</media>
</theme>
La solution
Just check registration.php file on UTF-8 BOM elements. This a symbol on the start of file what can be seen without special mode in editors.