Display Caption Text On Image Hover in WordPress

In this tutorial, i’ll show you how to use pure CSS code to:

  • Display an icon in place of your caption text
  • Display your caption text when the icon is hovered

Note: The solution in this post only works on images embedded in a post and not on featured images. You can take the HTML from the text editor after inserting an image and display it anywhere using a text widget or custom function.

WordPress generates 2 classes for captions which are displayed below your images by default:

.wp-caption { The main div your caption is wrapped in }

.wp-caption-text { A class for the caption text }

The following CSS code simply re-positions your caption text over your image and hides it until you hover over the image.

Demo Video

You could also use jQuery to hide and display text captions on images which we’ll cover in another tutorial.

Related Code Snippets


Comments

4 responses to “Display Caption Text On Image Hover in WordPress”

  1. thank you Brad, very nice technique. It is useful to add, that if you need full with caption background you have to add: right:0 after left:0.
    I have a question:
    do you know any method to make caption background clickable?
    now it’s like:
    [code]
    [caption][caption]
    I am thinking about
    [caption][caption]
    [/code]
    I’ve tried to do it manually but without success

    1. Brad Dalton Avatar
      Brad Dalton

      Support provided for members only.

  2. Thanks for tutorial! where though do u put our text for caption?

    1. Brad Dalton Avatar
      Brad Dalton

      In the image > caption field when inserting/uploading the image.

Leave a Reply

Join 5000+ Followers

Get The Latest Free & Premium Tutorials Delivered The Second They’re Published.