Cuberto / mouse-follower

A powerful javascript library to create amazing and smooth effects for the mouse cursor on your website.
MIT License
717 stars 60 forks source link

Post featured Image Link in Wordpress #29

Open LANSGraphix opened 1 year ago

LANSGraphix commented 1 year ago

jQuery(document).ready(function($) { $('.news-box h3 a') .attr('data-cursor-img', '/wp-content/uploads/2023/04/soccer_cover.jpg'); });

REFERENCE FROM THE ATTRIBUTE ABOVE, INSTEAD OF USING A LINK OF AN IMAGE, HOW CAN I SET THE DATA-CURSOR-IMG TO dynamicaly call the post featured image when $('.news-box h3 a') text link is hovered upon? Any clues?

alvarindev commented 1 year ago

you should write your code together with php!

luiskabes-arch commented 11 months ago
jQuery(document).ready(function($) { $('.news-box h3 a') .attr('data-cursor-img', '/wp-content/uploads/2023/04/soccer_cover.jpg'); });

REFERENCE FROM THE ATTRIBUTE ABOVE, INSTEAD OF USING A LINK OF AN IMAGE, HOW CAN I SET THE DATA-CURSOR-IMG TO dynamicaly call the post featured image when $('.news-box h3 a') text link is hovered upon? Any clues?

You need put an url of the featured image on the data-cursor-img, if you're make a custom template, you can do it like this

<?php
// Get the post's featured image URL
$featured_image_url = get_the_post_thumbnail_url(get_the_ID(), 'full');

// Output the HTML element with the data-cursor-img attribute
if ($featured_image_url) {
    echo '<div data-cursor-img="' . esc_attr($featured_image_url) . '">';
    // Your post content here...
    echo '</div>';
}
?>