0

Is there a way to load different fonts for different products in Magento2.4 ? The fonts will be self hosted in /web/fonts, but I want them to load only to specific products. Could be done in a block inside a product, something like <style>font-face {font-family: 'custom';src: url('fonts/custom.woff2');</style> ?

1 Answer 1

1

I don't know if you want to change the font for some products on category product listing pages or in product detail page.

But you can. If you want to change the font for some products in catalog/category pages you can go to the below path:

app/design/frontend/[Your Them Package]/[Your Theme]/Magento_Catalog/templates/product/list.phtml

And write the below code at the end of the file:

<?php if( $_product->getId() == [product id1] or $_product->getId() == [product id2]){ ?>
    <style> [your style ]</style>
<?php } ?>

or below one if the products are many:

$some_prd = array('product_id1', 'product_id2', 'product_id3' );
<?php if(in_array($_product->getId(), $some_prd)){ ?>
    <style> [your style ]</style>
<?php } ?>

Note: For any design customization, copy the file in child theme, change the file in the child theme and use the child theme. Don't modify the base/parent theme files.

1
  • I would like to load some custom font in the product details page. I was thinking if it could be done by creating a static block, where the font/css will load and call it through a widget to specific products. Feb 9 at 12:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.