How to display wishlist link (with functionality) in custom phtml file using template file in magento 2

1 Answer 1


You can try something like the following code:

<a href="#" data-post='<?php  echo $this->helper('Magento\Wishlist\Helper\Data')->getAddParams($_product) ?>' class="action towishlist" data-action="add-to-wishlist"><span>' .
__('Add to Wish List') . '</span></a>

Refer the below file and related block for more details


Make sure your custom module should use

<script type="text/x-magento-init">
    "*": {
        "Magento_Ui/js/core/app": {
            "components": {
                "wishlist": {
                    "component": "Magento_Wishlist/js/view/wishlist"
  • hi @Krishna, can you please update for Add to compare and send to an email as well please? May 12, 2020 at 6:32

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.