Solved

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

l1kim
Tourist
17 0 1

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
1335 295 328

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>

 

Buy me a Coffee


Enjoy Shopify for $1. Sign up now


For quick response - Message Me


Ping me at: theycallmemakka@gmail.com

View solution in original post

Replies 5 (5)

theycallmemakka
Shopify Partner
1335 295 328

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

Buy me a Coffee


Enjoy Shopify for $1. Sign up now


For quick response - Message Me


Ping me at: theycallmemakka@gmail.com

Raj-webdesigner
Shopify Partner
236 52 53

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

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 :-

Contribution



Contect On My Mail :-raj.s.webdevloper@gmail.com

l1kim
Tourist
17 0 1

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
1335 295 328

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>

 

Buy me a Coffee


Enjoy Shopify for $1. Sign up now


For quick response - Message Me


Ping me at: theycallmemakka@gmail.com

l1kim
Tourist
17 0 1

So amazing! It worked!

Thank you very much,