Magento – Remove block not working in custom xml layout

blockslayoutmagento2xml

I've created a custom layout xml for a page template and I am trying to remove some blocks that are being added to the page.

I've got template path hints on and have search through the site to find the reference to the .phtml file to find the name of the block and am then trying to remove the block using the below code however the blocks are still appearing on the page?

<referenceBlock name="skip_to_content.target" remove="true"/>
<referenceBlock name="page.main.title" remove="true"/>
<referenceBlock name="messages" remove="true"/>
<referenceBlock name="store_switcher" remove="true"/>

Can anyone please advise how I can remove blocks from the page?

Update:

<?xml version="1.0"?>
<!--
/**
 * Copyright © 2013-2017 Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_layout.xsd">
    <update handle="empty"/>
    <referenceContainer name="page.wrapper">
        <container name="header.container" as="header_container" label="Page Header Container" before="main.content"/>
        <container name="page.content" as="page_content" label="Page Content" after="header.container"/>
        <container name="footer-container" as="footer" before="before.body.end" label="Page Footer Container"/>
    </referenceContainer>
    <!-- Remove Default -->
    <referenceBlock name="skip_to_content.target" remove="true"/>
    <referenceBlock name="page.main.title" remove="true"/>

    <referenceBlock name="store_switcher" remove="true"/>
    <referenceBlock name="store_switcher" remove="true"/>
    <!-- Shop Home -->        
    <referenceContainer name="page.content">
        <block class="Magento\Framework\View\Element\Template" name="hero" template="Magento_Theme::html/hero.phtml"></block>
        <block class="Magento\Framework\View\Element\Template" name="shop-home-breadcrumbs" template="Magento_Theme::html/shop-home-breadcrumbs.phtml"></block>
        <block class="Magento\Framework\View\Element\Template" name="shop-home-categories" template="Magento_Theme::html/shop-home-categories.phtml"></block>
    </referenceContainer>
</layout>

Best Answer

I've managed to remove the blocks, however I still believe there must be a better way of achieving this:

I updated my default.xml to include:

<!-- Remove Blocks -->
<container name="delete"/>
<referenceContainer name="delete" remove="true" />

And in my custom layout xml I've moved the emails I would like to remove to the delete container:

<!-- Remove Default -->
<move element="skip_to_content.target" destination="delete"/>
<move element="page.main.title" destination="delete"/>
<move element="store_switcher" destination="delete"/>
<move element="messages" destination="delete"/>