3

I installed Sample data on magento2.

How do I remove this stylesheet from my theme?

<link  rel="stylesheet" type="text/css"  media="all" href="http://example.com/pub/media/styles.css" />

I have tried this in my default_head_blocks.xml:

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <head>
        <remove src="http://example.com/pub/media/styles.css/>"/>
    </head>
</page>

3 Answers 3

5

NORMALLY:

The <remove src=...> needs to match the string to include the CSS file. So don't insert a full URL, use the same string that caused the CSS file to be loaded.

For example, I edited the core (gasp!) and snuck the following two lines into a Magento_Customer module layout file for test purposes.

<css src="Magento_Customer::css/foo.css"/>
<remove src="Magento_Customer::css/foo.css"/>

If you just have the first line, the CSS file is included. If you include the second line, it removes it again. But it is doing the string compare using the string before being expanded to a URL (which makes sense as the domain name can change).

HOWEVER IN YOUR SPECIFIC EXAMPLE:

As the other reply correctly said, the URL to this particular CSS file is not injected by a layout file. Loading the Luma sample data puts a few bits of magic into the database directly. In this case it is the "HTML Head" with the magic {{MEDIA_URL}} string that injects it. So the approach I just described won't work as it manipulates the layout tree, not the final HTML.

So to remove, edit the "HTML Head" in the Admin UI to remove the injected link.

2
  • Thanks Alan! That answered my next question "How to remove Magento_Swatches/css/swatches.css?". In this case I changed <css src="Magento_Swatches::css/swatches.css"/> into <remove src="Magento_Swatches::css/swatches.css"/> in these two files: /VENDORNAME/THEMENAME/Magento_Swatches/layout/catalog_category_view.xml and /VENDORNAME/THEMENAME/Magento_Swatches/layout/catalog_product_view_type_configurable.xml.
    – Gordova
    Commented Jan 28, 2016 at 16:02
  • Does this same method apply for Js removal which is injected inside adminhtml store config head ?
    – Dev
    Commented Nov 17, 2016 at 17:16
4

Stores -> Configuration -> Design -> HTML Head

There is a textbox "Miscellaneous Scripts" where you can remove the CSS file.

4

on Magento ver. 2.1.3 with sample data

  • Go to menu Content > Design : Configuration
  • Edit default Global scope > Edit
  • Look at the bottom toggle "Other Settings" > HTML Head
  • Remove link rel="stylesheet" from Scripts and Style Sheets field

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.