0

Is there any way to have an image change on hover (from image a to image b) in wordpress? I wonder if there is a plugin or a custom function I can use to perform this.

P.S. -It is not a featured image for a post.

2

This isn't really a WordPress-specific question, but generally you can do something like this via CSS (depending on the structure of the image). Generally, you'll have an easier time doing this if the image in question is being applied as a background image to a DIV, rather than as just a standard img tag. Then, you can use the :hover CSS property to change the value for background-image.

See the accepted answer here to understand how to put this together:

https://stackoverflow.com/questions/18032220/css-change-image-src-on-imghover

  • Thank you for the response Greg, I know how to do that in a plain html with css and/or jquery, but I wonder how do I do that dynamically trough wp-admin dashboard. I was thinking to create a custom post and use 2 featured image as the image source but that takes effort indeed. – Pragmaticoder Feb 1 '17 at 7:33
  • I think a good approach to this would be to use the free plugin Advanced Custom Fields. This will let you create a couple of custom fields for a post, of type "Image". You can make the first Image field the intial state, and the second Image field the hover state. Then using ACF's functions in your template, you could snag the paths to the images dynamically. I.E., echo get_field('hover_image'); – Greg Burkett Feb 2 '17 at 3:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.