I have already solved my actual problem, but the reason that led to that error I do not understand. I am writing a wordpress child theme. In the functions.php a file is required.
require_once('templates/header.php');
in the file there are several functions:
<?php
add_action('generate_menu_bar_items', 'add_account_icon_menu');
function add_account_icon_menu()
{ ?>
<span class="menu-bar-item">
<a href="/my-account">
<span class="gp-icon">
<?= get_svg(["name" => "circle-user.svg"]) ?>
</span>
</a>
</span>
<?php } ?>
<?php
add_filter(
'generate_navigation_search_output',
function () {
printf(
'<form method="get" class="search-form navigation-search" action="%1$s">
<input type="search" placeholder="Enter your search term..." class="search-field" value="%2$s" name="s" title="%3$s" />
<input type="hidden" name="post_type" value="product" />
</form>',
esc_url(home_url('/')),
esc_attr(get_search_query()),
esc_attr_x('Search', 'label', 'generatepress')
);
}
);
?>
The point is on my local environment this worked great, but on my hosters websever I got the following error:
Warning: Cannot modify header information - headers already sent by (output started at /home/www/dev/wp-content/themes/generatepress-child/templates/header.php:1) in /home/www/dev/wp-includes/functions.php on line 6584
Warning: Cannot modify header information - headers already sent by (output started at /home/www/dev/wp-content/themes/generatepress-child/templates/header.php:1) in /home/www/dev/wp-admin/includes/misc.php on line 1310
Warning: Cannot modify header information - headers already sent by (output started at /home/www/dev/wp-content/themes/generatepress-child/templates/header.php:1) in /home/www/dev/wp-admin/admin-header.php on line 9
It took me a long time to figure out that empty lines between and/or before the functions cause these errors. Why this? Am I not allowed to have empty lines between PHP blocks?