I want do do changes in the following file:


How can I stop that file from being overwritten when doing upgrades in the future? Can I override it in some way, e.g. move it to the theme structure?


  • you can directly not change this file you can just overwritten in your custom create extension – Rakesh Donga Jan 30 '19 at 6:29

Create your custom module and add rewrite code in your custom module, please try following way.

Create custom module Vendor/Module


|_ composer.json

    "name": "vendor/module-module",
    "description": "",
    "type": "magento2-module",
    "license": "proprietary",
    "authors": [
            "name": "TestModule",
            "email": "info@test.com"
    "minimum-stability": "dev",
    "require": {},
    "autoload": {
        "psr-4": {
            "Vendor\\Module\\": ""
        "files": [



|_ etc/module.xml

<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Vendor_Module" setup_version="1.0.0"/>

|_ etc/di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
    <preference for="Vendor\Module\Block\Html\Notices" type="Magento\Cookie\Block\Html\Notices" />

|_ Block/Html/Notices.php (Please add your overrited code in this file )


 * Frontend form key content block
namespace Vendor\Module\Block\Html;

class Notices extends \Magento\Cookie\Block\Html\Notices

    public function getPrivacyPolicyLink()
        return $this->_urlBuilder->getUrl('privacy-policy-cookie-restriction-mode');

Please try this way and let me know if any issue.

| improve this answer | |
  • I did exactly like this, just changed the Vendor\Module to my namespace, and changed "privacy-policy-cookie-restriction-mode" to "privacy-policy" in the Notices.php file but it still shows the link to "privacy-policy-cookie-restriction-mode" – user2240778 Nov 20 '19 at 6:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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