kylephillips / favorites

Simple and flexible favorite buttons for any WordPress post type.
https://favoriteposts.com
223 stars 86 forks source link

[Feature Request]: Make thumbnails clickable #174

Open DivvyPT opened 1 year ago

DivvyPT commented 1 year ago

Hello guys, is there any way to make thumbnails clickable? I think that would be a great feature!

ryanhilton commented 4 months ago

Hey @DivvyPT, as a quick workaround, I added this JS to grab the favorite link, and then wrap the thumbnail image with it.

document.addEventListener('DOMContentLoaded', (event) => {

  let anchorLinks = document.querySelectorAll(".favorites-list p:nth-child(2) > a");

  anchorLinks.forEach((anchorLink) => {
      let image = anchorLink.parentNode.previousElementSibling.querySelector("img");

      let imageWrappedAnchor = document.createElement("a");
      imageWrappedAnchor.setAttribute("href", `${anchorLink.href}`);
      imageWrappedAnchor.appendChild(image);

      anchorLink.parentNode.previousElementSibling.appendChild(imageWrappedAnchor);
  });

});