0

I need to get the current url in the copyright.phtml section.

This is my code:

echo $this->getUrl('*/*/*', ['_current' => true, '_use_rewrite' => true]);

After clearing the cache it seems to work but when I change the page the link is always the same and doesn't change.

This problem only happens to me in the copyright.phtml section. Why?

1
  • Because it's coming from the cache. You can disable the cache but it will disable Full Page Caching for the whole page. And Footer is always there so it will slow your site. magento.stackexchange.com/a/103319 Commented Dec 22, 2020 at 16:52

1 Answer 1

1

If you really just want to echo the current URL you can do this

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
?>
<small class="copyright">
    <span><?= $block->escapeHtml($block->getCopyright()) ?></span>
    <p class="currentURL"></p>
</small>
<script type="text/javascript">
    require(["jquery","domReady!"], function ($) {

            var currentURL = window.location.href;
            $('.currentURL').text(currentURL);

    });
</script>

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.