Skip to content

Instantly share code, notes, and snippets.

@thagxt
Created August 25, 2016 14:10
Show Gist options
  • Save thagxt/6efbabd952c4b32e1661c167143dafb0 to your computer and use it in GitHub Desktop.
Save thagxt/6efbabd952c4b32e1661c167143dafb0 to your computer and use it in GitHub Desktop.
Magento 2 > product page > get Product URL, get Product Name and get Product ID
<?php
// get current page URL
$URL = $this->getUrl('*/*/*', ['_current' => true, '_use_rewrite' => true]);
// get current product name & ID
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManager->get('Magento\Framework\Registry')->registry('current_product'); //get current product
$id = $product->getId();
$title = $product->getName();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment