{"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 class=\"wp-block-paragraph\">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 class=\"wp-block-heading\" id=\"h-step-1-find-the-template\">Step 1. Find the Template <\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">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 class=\"wp-block-heading\" id=\"h-step-2-get-product-labels-helper\">Step 2.  Get Product Labels Helper<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">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\" data-line=\"\">&lt;?php\n\t\/** @var \\Plumrocket\\ProductLabels\\Helper\\Label $labelHelper *\/\n\t$labelHelper = $this-&gt;helper(\\Plumrocket\\ProductLabels\\Helper\\Label::class);\n?&gt;<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-step-3-render-labels\">Step 3. Render Labels<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">After the &lt;img&gt; tag, use the <code class=\"\" data-line=\"\">$labelHelper-&gt;getProductLabelsHtml($block-&gt;getLayout(), $_product);<\/code> code to get product labels HTML. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The <code class=\"\" data-line=\"\">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\" data-line=\"\">&lt;a href=&quot;&lt;?= $block-&gt;escapeUrl($_product-&gt;getProductUrl()) ?&gt;&quot; class=&quot;product photo product-item-photo&quot; tabindex=&quot;-1&quot;&gt;\n    &lt;img class=&quot;product-image-photo default_image&quot; src=&quot;&lt;?= $productImageUrl ?&gt;&quot; width=&quot;&lt;?= $image_width ?&gt;&quot; height=&quot;&lt;?= $image_height ?&gt;&quot;\/&gt;\n    &lt;?= $labelHelper-&gt;getProductLabelsHtml($block-&gt;getLayout(), $_product); ?&gt;\n&lt;\/a&gt;<\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><\/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,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[331],"tags":[],"class_list":["post-24074","post","type-post","status-publish","format-standard","hentry","category-magento-product-labels-v1-devguide","entry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\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 - Plumrocket Documentation\" \/>\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=\"author\" content=\"Plumrocket\" \/>\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 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 - Plumrocket Documentation","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","author":"Plumrocket","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Plumrocket","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/plumrocket.com\/docs\/magento-product-labels\/v1\/devguide\/product-labels-custom-templates#article","isPartOf":{"@id":"https:\/\/plumrocket.com\/docs\/magento-product-labels\/v1\/devguide\/product-labels-custom-templates"},"author":{"name":"Plumrocket","@id":"https:\/\/plumrocket.com\/docs\/#\/schema\/person\/c96fccdb89342ae6804272265723eca8"},"headline":"How to Display Magento Product Labels in Custom Templates","datePublished":"2021-09-28T11:07:47+00:00","dateModified":"2022-07-13T09:53:38+00:00","mainEntityOfPage":{"@id":"https:\/\/plumrocket.com\/docs\/magento-product-labels\/v1\/devguide\/product-labels-custom-templates"},"wordCount":128,"articleSection":["Developer Guide"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/plumrocket.com\/docs\/magento-product-labels\/v1\/devguide\/product-labels-custom-templates","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":"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":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/plumrocket.com\/docs\/#\/schema\/person\/c96fccdb89342ae6804272265723eca8","name":"Plumrocket","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/30d7e8cb4567485b56880a1658849a1252ac12806e8f95b3be71e986bf5eabee?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/30d7e8cb4567485b56880a1658849a1252ac12806e8f95b3be71e986bf5eabee?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/30d7e8cb4567485b56880a1658849a1252ac12806e8f95b3be71e986bf5eabee?s=96&d=mm&r=g","caption":"Plumrocket"}}]}},"_links":{"self":[{"href":"https:\/\/plumrocket.com\/docs\/wp-json\/wp\/v2\/posts\/24074","targetHints":{"allow":["GET"]}}],"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}]}}