Title: Image caption
Last modified: August 20, 2016

---

# Image caption

 *  Resolved [stoiko](https://wordpress.org/support/users/stoiko/)
 * (@stoiko)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/image-caption-4/)
 * I want a text caption over the image when you hover with the mouse, but I am 
   not sure how to do it in wordpress. I have this code:
 * <?php while (have_posts()) : the_post(); ?>
    “> <?php echo inkthemes_main_image();?
   > 
   
    <?php endwhile; ?>
 * And let’s say I want to use one of these captions:
    [http://www.hongkiat.com/blog/css3-image-captions/](http://www.hongkiat.com/blog/css3-image-captions/)
   How? I tried putting the style.css in the theme’s style, but still didn’t work…

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/image-caption-4/#post-3482775)
 * please re-post the code, and mark the code according to the forum guidelines 
   [http://codex.wordpress.org/Forum_Welcome#Posting_Code](http://codex.wordpress.org/Forum_Welcome#Posting_Code)
 * `inkthemes_main_image();` seems to be a custom function of your used theme;
 * what theme are you using?
 * what is the code behind this function?
 * you might need to post a link to your site to illustrate the image and text html
   in the context of the existing css.
 * for pure formatting or css questions, please ask at a css forum like [http://csscreator.com/forum](http://csscreator.com/forum)
 *  Thread Starter [stoiko](https://wordpress.org/support/users/stoiko/)
 * (@stoiko)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/image-caption-4/#post-3482958)
 *     ```
       <?php while (have_posts()) : the_post(); ?>
       <a href="<?php the_permalink(); ?>"> <?php echo inkthemes_main_image(); ?> </a></a>
       <?php endwhile; ?>
       ```
   
 * Themia Lite, inkthemes main image is a function that calls the posts’s main image.
 *     ```
       function inkthemes_main_image() {
           global $post, $posts;
           //This is required to set to Null
           $id = '';
           $the_title = '';
           // Till Here
           $permalink = get_permalink($id);
           $homeLink = get_template_directory_uri();
           $first_img = '';
           ob_start();
           ob_end_clean();
           $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
           if (isset($matches [1] [0])) {
               $first_img = $matches [1] [0];
           }
           if (empty($first_img)) { //Defines a default image
           } else {
               print "<a href='$permalink'><img src='$first_img' width='140px' height='208px' class='postimg wp-post-image' alt='$the_title' /></a>";
           }
       ```
   
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/image-caption-4/#post-3483002)
 * the posted code simply pulls the first image tag from the post’s content, which
   makes it virtually impossible to get the corresponding image caption.
 * however, the theme also seems to use the ‘featured image’ if it is used;
    this
   would make it easier to show the image caption.
 * then you will need to replicate the html and css structure from your example 
   site.
 *  Thread Starter [stoiko](https://wordpress.org/support/users/stoiko/)
 * (@stoiko)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/image-caption-4/#post-3483003)
 * I used other css caption and it worked!

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Image caption’ is closed to new replies.

## Tags

 * [caption](https://wordpress.org/support/topic-tag/caption/)
 * [hover](https://wordpress.org/support/topic-tag/hover/)
 * [image](https://wordpress.org/support/topic-tag/image/)
 * [text](https://wordpress.org/support/topic-tag/text/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 2 participants
 * Last reply from: [stoiko](https://wordpress.org/support/users/stoiko/)
 * Last activity: [13 years, 3 months ago](https://wordpress.org/support/topic/image-caption-4/#post-3483003)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
