How to add block to Magento 2 Luma Theme header?
Add this code in your default.xml file at below path
/app/code/design/frontend/MyCompany/MyTheme/Magento_Search/layout/default.xml
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="header-wrapper">
<block class="Magento\Framework\View\Element\Template" name="customFile" template="Magento_Search::customFile.phtml" />
</referenceContainer>
</body>
Now, create your template file at below path
/app/code/design/frontend/MyCompany/MyTheme/Magento_Search/templates/customFile.phtml
<div class="block" style="float: right;margin-bottom: 0.5%;margin-top: 0.5%;">
<?php echo __('This is Custom Text File'); ?>
</div>
Hope, It may be helpful for you.
Add below code at after top.search
referenceContainer:
app/code/design/frontend/[Package]/[Theme]/Magento_Search/layout/default.xml
<referenceContainer name="header-wrapper">
<block class="Magento\Cms\Block\Block" name="Promo">
<arguments>
<argument name="block_id" xsi:type="string">topPromo</argument>
</arguments>
</block>
</referenceContainer>
Note: Need to change block id topPromo
with your block Id and need some CSS for positioning.