You need to load product to get product name
With Object Manager
$productId = "10"; //Product Id
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManager->create('Magento\Catalog\Model\Product')->load($productId);
echo $product->getName(); //Get Product Name
Note: Don't use objectManager directly
With Factory Method
<?php
protected $product;
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Magento\Catalog\Model\ProductFactory $product
) {
$this->product = $product;
parent::__construct($context);
}
public function getProduct($id)
{
return $this->product->create()->load($id);
}
}
Then call getProduct
function in your phtml file
$productId = "10"; //Product Id
$product=$this->getProduct($productId);
echo $product->getName(); //Get Product Name
If you want to get in current product information in phtml you can use following code.
<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$currentProduct = $objectManager->get('Magento\Framework\Registry')->registry('current_product');//get current product information
echo $currentProduct>getId();
echo $currentProduct>getName();
?>