• Skip to primary navigation
  • Skip to main content
  • Skip to footer
  • Home
  • About
  • My Blogs
    • Photoblog
    • Knots
    • WP.com tips
kristarella.com

kristarella.com

Happiness Engineer at Automattic, lover of knitting, crochet, sci-fi and more

  • Presentations
  • Plugins
    • Exifography
  • Contact
You are here: Home / WordPress / Plugins / Exifography / Popup EXIF display with Thesography and jQuery

Popup EXIF display with Thesography and jQuery

18 October 2009 by kristarella

Contents
  1. via the title attribute
  2. display with javascript
    1. The CSS makes it look cool
    2. The javascript makes it act cool
      1. exif_popout() step by step
      2. What if I’m using auto-insertion in Thesis
      3. What if this doesn’t work with my post layout?

I received a request to make Thesography display EXIF upon hover over an image instead of just displaying as more text in the post. While I won’t include that kind of function in the plugin at this time (because I’m not sure how best to do it while maintaining a good amount of flexibility), I can show you how to implement it to suit your posting style.

EXIF via the title attribute

A very simple (though arguably non-semantic) way of doing this could be to display a tooltip via the title attribute.

EXIF displayed in a tooltip by Thesography
EXIF displayed in a tooltip by Thesography

When you insert your image into your WordPress post you can insert the Thesography shortcode into the title attribute via the HTML view.

<img src="http://www.example.com/wp-content/uploads/2009/10/lily.jpg" alt="lily" title="[exif id="18" show="all"]" width="800" height="529" class="aligncenter size-full wp-image-18" />

For this to work you must not have any HTML in the Thesography HTML display options. You should change the HTML options from the default to something like the following screenshot.

Thesography HTML options for tooltip display
Thesography HTML options for tooltip display

Fancy EXIF display with javascript

The first step to making a javascript EXIF display is to use CSS to style the EXIF block the way you want it.

Default Thesography style: list with a class of "exif"
Default Thesography style: list with a class of "exif"

The CSS makes it look cool

EXIF displayed by Thesography with custom CSS
EXIF displayed by Thesography with custom CSS

Using the following CSS (in your theme’s CSS file or custom.css when using the Thesis theme), along with a black 85% opacity background image, you can get a slightly transparent black sidebar over the left of your page.

You don’t have to use this particular CSS; it’s an example of the sort of thing you can do without having to recode your EXIF HTML. The javascript will apply to a range of different styles.

N.B. IE6 does not support position:fixed;, the list will appear below the image (where it was before) instead of overlayed on the page.

ul.exif {
	position:fixed;
	left:-2em;
	top:0;
	z-index:100;
	height:100%;
	width:16em;
	padding:10em 2em 2em;
	background:url(images/black-85.png) repeat;
	color:#fff;
	list-style-position:inside;
}

The javascript makes it act cool

To start, we need to add display:none; to the CSS so that ul.exif is hidden when the page loads.

The following PHP code can go in functions.php in the main directory of your theme, or in custom_functions.php if you’re using Thesis. If your theme doesn’t have a functions.php you can make one by creating a new file with that name (in a plain text editor, not MS Word or a rich text editor); add <?php at the start and paste this code after that.

if ( !is_admin() ) {
	wp_deregister_script('jquery'); 
	wp_register_script('jquery', ("http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"), false, '1.3.2'); 
	wp_enqueue_script('jquery');
}

function exif_popout() {
	if (is_single()) {
?>
<script type="text/javascript">
	$(function() {
		
		var hovered = 0;
		
		var maybeFadeOut = function() {
			if (hovered == 0) {
				$("ul.exif").fadeOut();
			}
		};
		
		var hoverOn = function() {
			$(this).parent().next("ul.exif").fadeIn();
			hovered++;
		};
		var hoverOff = function() {
			hovered--;
			setTimeout(maybeFadeOut, 0);
		};
		
		$(".post img").hover(hoverOn, hoverOff);
		$("ul.exif").hover(hoverOn, hoverOff);
	});
</script>
<?php
	}
}
add_action('wp_head','exif_popout');

The first chunk of code is from Digging into WordPress and it loads the latest (at time of writing) jQuery library, hosted by Google. Using externally hosted libraries can be good because you have easy access to the latest files and because they can load asynchronously (i.e., while something from your server is loading, this can load too because it’s on another server, things from your server only load one at a time).

The second chunk of code inserts javascript into the head of our HTML WordPress page.

exif_popout() step by step

If you need more info about basic PHP syntax try the Tizag PHP tutorial. On Tizag.com you can also find HTML and CSS tutorials.

The function exif_popout() is designed to load only on single post pages (if (is_single()) determines that). It is also designed to be useful when there are multiple images on the page, each with their own EXIF that comes right after the image in the post.

$(function() { ... }); instructs jQuery to run our function when the webpage has completed loading.

var hovered = 0; is a variable that acts as a counter getting increased or decreased as we move our mouse over and off the image or the EXIF block. It helps determine how the movement of the mouse indicates whether the EXIF should be visible or not.

maybeFadeOut is a function that when called says, if hovered is equal to zero all EXIF blocks should be hidden (with a fade out effect).

hoverOn is a function that when called takes the element it acts upon ($(this), in this case it’s the image), then it finds that element’s parent element (using parent(), which in WordPress posts will be a paragraph, because images on their own line get wrapped in a paragraph). It then finds the ul.class that is next to that paragraph (next("ul.exif")) and displays it with a fade in effect. The hovered counter is also increased.

hoverOff is a function that when called decreases the hovered counter and activates the maybeFadeOut function. maybeFadeOut is wrapped with setTimeout, which adds a delay (of zero milliseconds) to the execution of maybeFadeOut and moves it to the end of the current action queue; allowing the rest of the javascript to execute before it. This allows us to move our mouse off the image and onto the EXIF block, or off the block onto the image, without the EXIF fading out and back in again (i.e., the fade out is delayed until we really want it to disappear — when we’re not hovering on the image or the EXIF).

$(".post img").hover(hoverOn, hoverOff);
$("ul.exif").hover(hoverOn, hoverOff);

Those two lines activate hoverOn and hoverOff when you hover your mouse on and off .post img and ul.exif.

.post is a class assigned to the element containing your image. If your theme uses a different class for your posts you need to change that in the javascript. Also, ul.exif is an unordered list with a class of “exif”, which is the default display for Thesography. If you have changed the way that Thesography displays, you will need to change ul.exif to whatever element your EXIF is presented with.

What if I’m using auto-insertion in Thesis

If you’re using Thesography auto-insertion with Thesis and you have some text in between the image and the EXIF the javascript won’t work as written because ul.exif won’t be the next thing after the image paragraph, there will be another paragraph (or more) in between. However, if you’re using auto-insertion it means you’ve only got one lot of EXIF on the page and you can change $(this).parent().next("ul.exif").fadeIn(); to $("ul.exif").fadeIn();.

What if this doesn’t work with my post layout?

There are so many different ways that your images and EXIF could be laid out in a post; it’s impossible for me to predict them all.

If you want to wrap your image and EXIF in a div together, that might simplify things for you and you could look into using the siblings selector instead of parent().next("ul.exif"), or perhaps parent().children("ul.exif").

Alternatively, while writing your post you could wrap each image and its related EXIF in paragraphs or divs with a unique class for each pair, and then use the class attribute as a variable to identify which EXIF should be displayed.

For more info on how to identify and navigate elements with jQuery, check the jQuery documentation; particularly Selectors and Traversing.

If you have trouble making the javascript fit your posting style and ask for help, please be very specific with the way your posts are displayed. A link to a direct example or the source code of an example (perhaps copied into Pastebin) is preferable.

Share this:

  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on X (Opens in new window) X
  • Click to share on Pocket (Opens in new window) Pocket

Like this:

Like Loading...

Related

Filed Under: Exifography, Thesis, Tutorials Tagged With: CSS, geek, PHP

Reader Interactions

Comments

  1. morten says

    18 October 2009 at 19:49

    Hi,

    I added the code in css and functions.php as you have described, but nothing has changed – title attribute is displayed as before…..

    Morten

  2. kristarella says

    18 October 2009 at 23:45

    Morten — The title attribute and the javascript approach are two entirely separate methods, the first achieving an extremely simplified version of the second (pop up info when hovering).

    The EXIF needs to already be displayed in your post, either by shortcode, or by adding the display functions into your template files. Then it can be styled, hidden, and manipulated by javascript. The javascript doesn’t just render the EXIF data on the fly. The EXIF data retrieval needs to be done on the PHP processing side before the HTML of the page is rendered. This javascript method only manipulates what you’ve already got displayed by Thesography. If you don’t have anything displayed by Thesography yet, it won’t do anything.

  3. Lares says

    25 February 2010 at 01:51

    Thanks

A triptych of baubles. These are very satisfying t A triptych of baubles. These are very satisfying to paint ❤️💚💙

#watercolor #watercolour #christmas
I have really enjoyed this Christmassy painting! S I have really enjoyed this Christmassy painting! So glad my friend asked me to make some cards for our church helpers, because it set me on a roll!
#watercolor #watercolour #christmas #christmascards #watercolorcards
Had a great Saturday at the GKR Karate State Title Had a great Saturday at the GKR Karate State Titles! I was a sub for @jamesxuereb.me in the Blue Flame Dragons thanks to his sprained ankle; we won first round and came fourth overall!
I did a bunch of judging and officiating, which was really good.
I didn’t place in my individual events, but had a very fun final round of kumite (sparring).

#gkrkarate #karate
More stamping tonight. Even better than last night More stamping tonight. Even better than last night’s!
Did some stamping this evening. Love it! I wish I’d done some pages in other ink colours before I dismantled the stamps 😂
Had an appointment in the city, so I got to visit Had an appointment in the city, so I got to visit the @legocertifiedstores_anz Wicked display!
#wicked #lego #afol #sydney
A little book I made from Bunnings paint sample ca A little book I made from Bunnings paint sample cards. It’s going to be for mini paintings and collages. Sometimes it’s nice to start with a colour rather than a blank white page!
A little while ago I did some swatching of Daniel A little while ago I did some swatching of Daniel Smith and Schminke Horodam watercolours. So soothing! I love some of the granulating colours!
#watercolours
Follow on Instagram

Footer

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Top Posts & Pages

  • Home
    Home
  • 2020: the year that wasn't
    2020: the year that wasn't
  • The Voice Referendum
    The Voice Referendum
  • Clickable tags for WordPress
    Clickable tags for WordPress
  • Edit EPS files in Inkscape on Mac
    Edit EPS files in Inkscape on Mac
  • Exifography
    Exifography

Follow Me On…

  • Instagram
  • X
  • GitHub
  • LinkedIn
  • YouTube

Categories

Copyright © 2025 · Kristen Symonds · kristarella.com

%d