I am using magento 2.4.6 One of my modules is adding meta tags in catalog. Not my code
case 'catalog_product_view':
$currentProduct = $this->_registry->registry('current_product');
if ($currentProduct && $currentProduct->getData('enable_index_follow')) {
$indexValue = $currentProduct->getData('index_value');
$followValue = $currentProduct->getData('follow_value');
$indexFollowValue = $this->_indexFollowBuilder->getIndexFollowValue($indexValue, $followValue);
$this->_pageConfig->setRobots($indexFollowValue);
}
if ($currentProduct && $currentProduct->getData('enable_canonical_url')) {
$canonicalUrl = $currentProduct->getData('canonical_url');
$urlOptions = parse_url($canonicalUrl);
if (!isset($urlOptions['scheme'])) {
$canonicalUrl = $baseUrl . $canonicalUrl;
}
$this->_pageConfig->addRemotePageAsset(
$canonicalUrl,
'canonical',
['attributes' => ['rel' => 'canonical']]
);
}
break;
Line:
$urlOptions = parse_url($canonicalUrl);
throw error:
Deprecated Functionality: parse_url(): Passing null to parameter #1 ($url) of type string is deprecated
I can't fix it.
Any help please?
2 Answers 2
Instead of null you can use empty string.
chnage below code from
$canonicalUrl = $currentProduct->getData('canonical_url');
to
$canonicalUrl = $currentProduct->getData('canonical_url') ?? '';
answered Jul 14, 2023 at 4:05
Pawan
6,1213 gold badges19 silver badges39 bronze badges
Please try this once, Hope it will work.
Repalce from :-
$urlOptions = parse_url($canonicalUrl);
Repalce to :-
$urlOptions = parse_url($canonicalUrl ?? '');
Explore related questions
See similar questions with these tags.
default