How to auto update the copyright year in the footer section of the site in Magento 2.

enter image description here


7 Answers 7


One possible hack can help us to modify the year dynamically.

Go to -> Admin -> General, choose Design -> Expand the Footer section and paste the below code.

Copyright © <script>document.write(new Date().getFullYear())</script> Magento. All rights reserved.

Remove the cache and check.

  • Hi Thanks for your answer I'll try this one also Dec 26, 2016 at 10:01
  • This gets the job done but I do have to wonder if search engine site spiders will pick up the correct copyright year.
    – jschrab
    Jan 12, 2018 at 21:28
  • 6
    This doesn't work on 2.2.2 as it doesn't accept html elements. Aug 19, 2019 at 8:23
  • document.write(new Date().getFullYear()) is deprecated. Is there an PHP version of the same thing? May 7, 2020 at 19:04

Place the following contents in this file:


<?php /* @escapeNotVerified */ echo preg_replace('/(^|\s)(\d{4})(\s|$)/m', " ".date('Y'). " ", $block->getCopyright()); ?>
  • 3
    I like this solution the best - it gives you control over the text, yet flexibility for the copyright year to change. What I do to extend this is <?= /* @escapeNotVerified */ str_ireplace('{{year}}', date('Y'), $block->getCopyright()) ?> ... and then use "{{year}}" copyright text in the footer admin. That way I can have full control over the text along with the auto-updating year.
    – jschrab
    Jan 12, 2018 at 21:27

Place the following contents in this file: {theme_dir}/Magento_Theme/templates/html/copyright.phtml

<small class="copyright">
    <span>Copyright &copy; You <?php echo date('Y') ?>, All Rights Reserved.</span>

Then flush the cache.

  • Hello Thanks for this answor I'll try this one.Thanks Aaron :) Dec 26, 2016 at 10:11

This how I would do it. overwrite copyright.phtml:

 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
<small class="copyright">
    <span><?= /* @escapeNotVerified */ str_replace ( '{{year}}', date('Y'), $block->getCopyright()) ?></span>

Then go to Content->Design->Configuration Choose a theme Edit->footer->copyright add this:

Copyright © {{year}} Magento. All rights reserved.


  • this helped me. May 7, 2020 at 19:39

The best way to do this would be by creating an after plugin on the getCopyright method in Magento\Theme\Block\Html\Footer. It is not good practice to add logic in a template.

Add the following in a custom module in the etc/frontend/di.xml file

<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Theme\Block\Html\Footer">
        <plugin name="Vendor_Module::UpdateCopyrightWithCurrentYear" type="Vendor\Module\Plugin\Theme\Block\Html\Footer\UpdateCopyrightWithCurrentYear" />

create Plugin/Theme/Block/Html/Footer/UpdateCopyrightWithCurrentYear.php within you module:

namespace Vendor\Module\Plugin\Theme\Block\Html\Footer;

use Magento\Theme\Block\Html\Footer;

class UpdateCopyrightWithCurrentYear
     * @param Footer $subject
     * @param string $result
     * @return string $result
    public function afterGetCopyright(Footer $subject, $result)
        $result = preg_replace_callback(
            function($matches) {
                return $matches[2] != date('Y')?$matches[1] . $matches[2].' - '.date('Y') . $matches[3]:$matches[0];
        return $result;

I borrowed Krishna ijjada's regex to match the year. Also this adds the current year in the copyright message so that the year when copyright started also stays visible.


It is necessary to think of the timezone, here is my answer ( {theme_dir}/Magento_Theme/templates/html/copyright.phtml ):

/* @var $block \Magento\Theme\Block\Html\Footer */

use Magento\Framework\App\ObjectManager;
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;

$year = ObjectManager::getInstance()->get( TimezoneInterface::class )->date()->format( 'Y' );
<small class="copyright">
    <span><?= /* @escapeNotVerified */ $block->escapeHtml( __( 'Copyright &copy; %1 xxx.', $year ) ) ?></span>
  • Why is timezone necessary? There's only a few hours per year where this might show the wrong year which is highly unlikely to bother any user.
    – Jacques
    Feb 28, 2023 at 11:31

To Add a dynamic year in the footer copyright section use this mobile under System -> Configuration -> Design. Ability to show a year variable via the Theme Footer configuration

Here is a module used this year that will change dynamically. Even the PWA app year will change if you use this extension in Magento PWA.


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.