{"id":24074,"date":"2021-09-28T07:07:47","date_gmt":"2021-09-28T11:07:47","guid":{"rendered":"https:\/\/plumrocket.com\/docs\/?p=24074"},"modified":"2022-07-13T05:53:38","modified_gmt":"2022-07-13T09:53:38","slug":"how-to-display-product-labels-in-custom-templates","status":"publish","type":"post","link":"https:\/\/plumrocket.com\/docs\/magento-product-labels\/v1\/devguide\/product-labels-custom-templates","title":{"rendered":"How to Display Magento Product Labels in Custom Templates"},"content":{"rendered":"\n<p>In this developer guide article for <a href=\"https:\/\/plumrocket.com\/magento-product-labels\">Product Labels Magento 2 Extension<\/a>, you can find out how to display product labels on product images rendered by custom or third-party functionality. Additionally, this guide helps resolve compatibility issues with third-party themes that modify templates so that product labels no longer appear automatically. Please follow the steps below to display product labels in custom templates.<\/p>\n\n\n\n<h2 id=\"h-step-1-find-the-template\">Step 1. Find the Template <\/h2>\n\n\n\n<p>Find your custom template with the help of <a href=\"https:\/\/docs.magento.com\/user-guide\/system\/template-path-hints.html\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">path hints<\/a>.<\/p>\n\n\n\n<h2 id=\"h-step-2-get-product-labels-helper\">Step 2.  Get Product Labels Helper<\/h2>\n\n\n\n<p>Add the following code at the beginning of the template:<\/p>\n\n\n\n<div class=\"wp-block-prismatic-blocks\"><div><\/div><pre><code class=\"language-php\">&lt;?php\n\t\/** @var \\Plumrocket\\ProductLabels\\Helper\\Label $labelHelper *\/\n\t$labelHelper = $this->helper(\\Plumrocket\\ProductLabels\\Helper\\Label::class);\n?><\/code><\/pre><\/div>\n\n\n\n<h2 id=\"h-step-3-render-labels\">Step 3. Render Labels<\/h2>\n\n\n\n<p>After the &lt;img&gt; tag, use the <code>$labelHelper-&gt;getProductLabelsHtml($block-&gt;getLayout(), $_product);<\/code> code to get product labels HTML. <\/p>\n\n\n\n<p>The <code>getProductLabelsHtml<\/code> method requires two arguments: <a href=\"https:\/\/github.com\/magento\/magento2\/blob\/2.4\/lib\/internal\/Magento\/Framework\/View\/LayoutInterface.php\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">Layout<\/a> and <a href=\"https:\/\/github.com\/magento\/magento2\/blob\/2.4\/app\/code\/Magento\/Catalog\/Api\/Data\/ProductInterface.php\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">Product<\/a>.<\/p>\n\n\n\n<div class=\"wp-block-prismatic-blocks\"><div class=\"prism-title\">Third-party theme integration example <\/div><pre><code class=\"language-php\">&lt;a href=\"&lt;?= $block->escapeUrl($_product->getProductUrl()) ?>\" class=\"product photo product-item-photo\" tabindex=\"-1\">\n    &lt;img class=\"product-image-photo default_image\" src=\"&lt;?= $productImageUrl ?>\" width=\"&lt;?= $image_width ?>\" height=\"&lt;?= $image_height ?>\"\/>\n    &lt;?= $labelHelper->getProductLabelsHtml($block->getLayout(), $_product); ?>\n&lt;\/a><\/code><\/pre><\/div>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this developer guide article for Product Labels Magento 2 Extension, you can find out how to display product labels on product images rendered by custom or third-party functionality. Additionally, this guide helps resolve compatibility issues with third-party themes that modify templates so that product labels no longer appear automatically. Please follow the steps below &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/plumrocket.com\/docs\/magento-product-labels\/v1\/devguide\/product-labels-custom-templates\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to Display Magento Product Labels in Custom Templates&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[331],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v17.2 (Yoast SEO v17.2) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Display Magento Product Labels in Custom Templates - Plumrocket Documentation<\/title>\n<meta name=\"description\" content=\"In this developer guide article for Product Labels Magento 2 Extension, you can find out how to display product labels on product images rendered by\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/plumrocket.com\/docs\/magento-product-labels\/v1\/devguide\/product-labels-custom-templates\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Display Magento Product Labels in Custom Templates\" \/>\n<meta property=\"og:description\" content=\"In this developer guide article for Product Labels Magento 2 Extension, you can find out how to display product labels on product images rendered by\" \/>\n<meta property=\"og:url\" content=\"https:\/\/plumrocket.com\/docs\/magento-product-labels\/v1\/devguide\/product-labels-custom-templates\" \/>\n<meta property=\"og:site_name\" content=\"Plumrocket Documentation\" \/>\n<meta property=\"article:published_time\" content=\"2021-09-28T11:07:47+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-07-13T09:53:38+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Plumrocket\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"How to Display Magento Product Labels in Custom Templates - Plumrocket Documentation","description":"In this developer guide article for Product Labels Magento 2 Extension, you can find out how to display product labels on product images rendered by","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/plumrocket.com\/docs\/magento-product-labels\/v1\/devguide\/product-labels-custom-templates","og_locale":"en_US","og_type":"article","og_title":"How to Display Magento Product Labels in Custom Templates","og_description":"In this developer guide article for Product Labels Magento 2 Extension, you can find out how to display product labels on product images rendered by","og_url":"https:\/\/plumrocket.com\/docs\/magento-product-labels\/v1\/devguide\/product-labels-custom-templates","og_site_name":"Plumrocket Documentation","article_published_time":"2021-09-28T11:07:47+00:00","article_modified_time":"2022-07-13T09:53:38+00:00","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Plumrocket","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebSite","@id":"https:\/\/plumrocket.com\/docs\/#website","url":"https:\/\/plumrocket.com\/docs\/","name":"Plumrocket Documentation","description":"Extensions docs, troubleshootings etc.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/plumrocket.com\/docs\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/plumrocket.com\/docs\/magento-product-labels\/v1\/devguide\/product-labels-custom-templates#webpage","url":"https:\/\/plumrocket.com\/docs\/magento-product-labels\/v1\/devguide\/product-labels-custom-templates","name":"How to Display Magento Product Labels in Custom Templates - Plumrocket Documentation","isPartOf":{"@id":"https:\/\/plumrocket.com\/docs\/#website"},"datePublished":"2021-09-28T11:07:47+00:00","dateModified":"2022-07-13T09:53:38+00:00","author":{"@id":"https:\/\/plumrocket.com\/docs\/#\/schema\/person\/c96fccdb89342ae6804272265723eca8"},"description":"In this developer guide article for Product Labels Magento 2 Extension, you can find out how to display product labels on product images rendered by","breadcrumb":{"@id":"https:\/\/plumrocket.com\/docs\/magento-product-labels\/v1\/devguide\/product-labels-custom-templates#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/plumrocket.com\/docs\/magento-product-labels\/v1\/devguide\/product-labels-custom-templates"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/plumrocket.com\/docs\/magento-product-labels\/v1\/devguide\/product-labels-custom-templates#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Magento 2 Extensions","item":"https:\/\/plumrocket.com\/magento-extensions"},{"@type":"ListItem","position":2,"name":"Magento 2 Product Labels","item":"https:\/\/plumrocket.com\/magento-product-labels"},{"@type":"ListItem","position":3,"name":"Documentation","item":"https:\/\/plumrocket.com\/docs\/magento-product-labels"},{"@type":"ListItem","position":4,"name":"v1","item":"https:\/\/plumrocket.com\/docs\/magento-product-labels\/v1"},{"@type":"ListItem","position":5,"name":"Developer Guide","item":"https:\/\/plumrocket.com\/docs\/magento-product-labels\/v1\/devguide"},{"@type":"ListItem","position":6,"name":"How to Display Magento Product Labels in Custom Templates"}]},{"@type":"Person","@id":"https:\/\/plumrocket.com\/docs\/#\/schema\/person\/c96fccdb89342ae6804272265723eca8","name":"Plumrocket","image":{"@type":"ImageObject","@id":"https:\/\/plumrocket.com\/docs\/#personlogo","inLanguage":"en-US","url":"https:\/\/secure.gravatar.com\/avatar\/10c44aa45aab391250913d982e552e53?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/10c44aa45aab391250913d982e552e53?s=96&d=mm&r=g","caption":"Plumrocket"}}]}},"_links":{"self":[{"href":"https:\/\/plumrocket.com\/docs\/wp-json\/wp\/v2\/posts\/24074"}],"collection":[{"href":"https:\/\/plumrocket.com\/docs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/plumrocket.com\/docs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/plumrocket.com\/docs\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/plumrocket.com\/docs\/wp-json\/wp\/v2\/comments?post=24074"}],"version-history":[{"count":12,"href":"https:\/\/plumrocket.com\/docs\/wp-json\/wp\/v2\/posts\/24074\/revisions"}],"predecessor-version":[{"id":25830,"href":"https:\/\/plumrocket.com\/docs\/wp-json\/wp\/v2\/posts\/24074\/revisions\/25830"}],"wp:attachment":[{"href":"https:\/\/plumrocket.com\/docs\/wp-json\/wp\/v2\/media?parent=24074"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/plumrocket.com\/docs\/wp-json\/wp\/v2\/categories?post=24074"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/plumrocket.com\/docs\/wp-json\/wp\/v2\/tags?post=24074"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}