WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using Wordpress Gallery shortcode and I was wondering if there is a way to navigate using the arrow keys? Like if I view an single image and used the right arrow to navigate to the next image in the gallery set. Any idea how to do this?

share|improve this question
You could use javascript. – Cthulhu Oct 22 '12 at 15:05
I'm not a programmer so I would prefer if there's a plugin – Ruriko Oct 22 '12 at 23:40
Plugin recommendation is off-topic now... & there are plenty of Imagebox plugins in the Repository, surely one or more will have this feature. – brasofilo Oct 26 '12 at 18:21
up vote 2 down vote accepted

The Underscores (_s) starter theme comes with a keyboard navigation script for this. I haven't tested this myself though. But the JS file looks like this:

jQuery( document ).ready( function( $ ) {
    $( document ).keydown( function( e ) {
        var url = false;
        if ( e.which == 37 ) {  // Left arrow key code
            url = $( '.previous-image a' ).attr( 'href' );
        else if ( e.which == 39 ) {  // Right arrow key code
            url = $( '.entry-attachment a' ).attr( 'href' );
        if ( url && ( !$( 'textarea, input' ).is( ':focus' ) ) ) {
            window.location = url;
    } );
} );

It also needs some modifications to your attachment theme file to make the links work correctly. My suggestion is that you download the _s theme and take a look in the image.php file.

Basically what you need on the attachment page is a link to the next/prev image inside an element with the class "previous-image" / "entry-attachment".

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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