Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Post featured Image Link in Wordpress #29

Open
LANSGraphix opened this issue Apr 4, 2023 · 2 comments
Open

Post featured Image Link in Wordpress #29

LANSGraphix opened this issue Apr 4, 2023 · 2 comments

Comments

@LANSGraphix
Copy link

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
Copy link

you should write your code together with php!

@luiskabes-arch
Copy link

luiskabes-arch commented Aug 3, 2023

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>';
}
?>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants