How to add external CSS and JS Url in Magento2?

You can add External third-party JS,CSS, and fonts URL using Magento 2 by XML at below way, All the Url will be staying in  <head> tag. Pass Second attribute as  src_type=”url”

For set third-party JS link,

<head>
	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js" src_type="url" />
</head>

For set third-party CSS link,

<head>
	<css src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css" src_type="url" />
</head>

For set font link,

<head>
	<link src="http://fonts.googleapis.com/css?family=Montserrat" src_type="url" />
</head>

For Remove link from the page,  If you want to remove specific JS or CSS from the specific page you can use <remove> tag under the <head> to remove from a specific page.

<head>
    <remove src="ttps://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js" />
    <remove src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css" />
    <remove src="http://fonts.googleapis.com/css?family=Montserrat" />
</head>

 

How to get backend Url in Magento 2?

It’s quite easy to fetch Base URL for an Admin panel/Backend in Magento 2 using Backend module Url Class.

Back end Url have base store Url plus admin URI name. like {BASE_URL}/admin/

You can get Magento2 backend URL by just below way,

public function __construct(
    \Magento\Backend\Model\Url $backendUrlManager
) {
    $this->backendUrlManager  = $backendUrlManager;
}

public function getBackendUrl()
{
    return $this->backendUrlManager->getUrl('sales/order/view', ['param1' => 'param1']);
}

We have passed Sales/order/view action with a query string as param1 in URL.

Get URL from an adminhtml template or PHP file,
echo $this->getBackendUrl();

How to get product image url in Magento 2?

In the e-Commerce Site, Each Product contains unique images like Small Images, Base images, and thumbnail images.

Many times in custom development we need to required get the product URL in Magento 2. If you are developing some features related to images and want to retrieve the image URL, You can achieve the image full URL by referring to this article.

If you are dealing with PWA stuff and want to fetch the product image URL by GraphQL, Get Product Image URLs with GraphQl Continue reading “How to get product image url in Magento 2?”