Have your say in Community Polls: What was/is your greatest motivation to start your own business?

How to Make Featured Product Image and Title Clickable (Craft Theme)

Solved

How to Make Featured Product Image and Title Clickable (Craft Theme)

l1kim
Excursionist
30 0 3

Hello,

 

How do you make both image and title of "Featured Product" clickable to its product page?

I would like it to be clickable WITHOUT underlining the Product Title as a link. 

 

https://putonlovemarket.com

 

Screenshot 2024-03-22 at 4.06.49 PM.png

Accepted Solution (1)
theycallmemakka
Shopify Partner
1729 419 437

This is an accepted solution.

Hi @l1kim ,

 

Try replacing the previous code with the below code. Also do not forget to like and mark the answer as accepted.

<script>
function getClosestViewDetailsLink(element) {
    return element.closest('.featured-product').querySelector('.product__view-details');
}

function handleClick(event) {
    var closestLink = getClosestViewDetailsLink(event.currentTarget);
    if (closestLink) {
        window.location.href = closestLink.href;
    }
}

document.querySelectorAll('.featured-product .product__media-item')?.forEach(function(t){
    t.addEventListener('click', handleClick);
});
document.querySelectorAll('.featured-product .product__title')?.forEach(function(t){
    t.addEventListener('click', handleClick);
});


</script>
<style>
.featured-product .product__title {
    cursor: pointer;
}
</style>

 

Support Me: Buy me a Coffee


For quick response - Message Me


Ping me at: theycallmemakka@gmail.com

View solution in original post

Replies 7 (7)

theycallmemakka
Shopify Partner
1729 419 437

Hi @l1kim 

Follow these Steps:

1) Go to Online Store
2) Edit Code
3) Find theme.liquid file
4) Add the following code just above tag </body>

<script>
function getClosestViewDetailsLink(element) {
    return element.closest('.featured-product').querySelector('.product__view-details');
}

function handleClick(event) {
    var closestLink = getClosestViewDetailsLink(event.currentTarget);
    if (closestLink) {
        window.location.href = closestLink.href;
    }
}

document.querySelector('.featured-product .product__media-item')?.addEventListener('click', handleClick);

document.querySelector('.featured-product .product__title')?.addEventListener('click', handleClick);

</script>
<style>
.featured-product .product__title {
    cursor: pointer;
}
</style>

 

If you require further help to optimize your store, please don’t hesitate to reach out. If you find this information useful, a Like would be greatly appreciated. And if this solves the problem, please Mark it as Solution!

 

Best Regards,
Makka

Support Me: Buy me a Coffee


For quick response - Message Me


Ping me at: theycallmemakka@gmail.com

Raj-webdesigner
Shopify Partner
349 87 82

Follow these Steps:

1) Go to Online Store
2) Edit Code
3) Find Base.css file



Add this option if you just want to Only click on product total Than Put This Css

 

@media screen and (min-width: 767px){
       .collection .card__heading a:after{
		display:none;
	}
}

 

Otherwise This Css 

 

.collection .underline-links-hover:hover a{
	text-decoration: none;	
}

 

And if you want to do both Than Put This Css

 

.collection .underline-links-hover:hover a{
	text-decoration: none;	
}
@media screen and (min-width: 767px){
	.collection .card__heading a:after{
		display:none;
	}
}

 


If you require further help to optimize your store, please don’t hesitate to reach out. If you find this information useful, a Like would be greatly appreciated. And if this solves the problem, please Mark it as Solution!

Best Regards,
Raj-Webdesigner

Are you looking for Shopify Developer then your search is over I will help you


If you require further help to optimize your store, please don’t hesitate to reach out.


This contribution will always benefit you and you will get my full help easily and you can contact me easily.


Your Willpower Contribution Link

:-

❤️Tip❤️

Contect On My Mail :-Mail@gmail.com


l1kim
Excursionist
30 0 3

Hmm.. This worked only for the top product but not the product underneath. Would you please help me do the same for the 2nd product the one right under it?

 

 

https://putonlovemarket.com/pages/candle-workshop

theycallmemakka
Shopify Partner
1729 419 437

This is an accepted solution.

Hi @l1kim ,

 

Try replacing the previous code with the below code. Also do not forget to like and mark the answer as accepted.

<script>
function getClosestViewDetailsLink(element) {
    return element.closest('.featured-product').querySelector('.product__view-details');
}

function handleClick(event) {
    var closestLink = getClosestViewDetailsLink(event.currentTarget);
    if (closestLink) {
        window.location.href = closestLink.href;
    }
}

document.querySelectorAll('.featured-product .product__media-item')?.forEach(function(t){
    t.addEventListener('click', handleClick);
});
document.querySelectorAll('.featured-product .product__title')?.forEach(function(t){
    t.addEventListener('click', handleClick);
});


</script>
<style>
.featured-product .product__title {
    cursor: pointer;
}
</style>

 

Support Me: Buy me a Coffee


For quick response - Message Me


Ping me at: theycallmemakka@gmail.com

l1kim
Excursionist
30 0 3

So amazing! It worked!

Thank you very much,

kingbeehkb
Visitor
2 0 0

Hello,

 

I've used this code for the same purpose and it actually worked perfectly which I truly thank you for. But it causes some weird issue.
so when I zoom in (on mobile) on the product photo the page either refreshes or crashes! 
Would you actually be able to check that and help me with it? 

l1kim
Excursionist
30 0 3

Hello, I’m not sure why it would crash on your end… since I’m not an expert at this. Maybe write a new post about it asking for help?