0

I have a next_image_link and previous_image_link as a navigation on my image.php but I want the first and last image to echo greyed out text (disabled button) to show prev button and next button.

Right now, my code doesn't echo it when you are in the first or last image.

< | next >

I want to display something like this (where the bold text is a link) when you are in the first image

< previous | next >

And like this when you are in the last

< previous | next >

Currenty, I have this code:

<?php 
    next_image_link( false, '<div class="next-image">' . '<i class="fa fa-angle-left"></i> <span>PREV</span>' . '</div>' );
    previous_image_link( false, '<div class="previous-image">' . '<span>NEXT</span> <i class="fa fa-angle-right"></i>' . '</div>' ); 
?>
1

You need to use the adjacent image link filters, defined in the source of adjacent_image_link() function.

Example:

add_filter( "next_image_link", "cyb_next_image_link", 10, 4 );
function cyb_next_image_link( $output, $attachment_id, $size, $text ) {

    if( $output == '' ) {
        return '<div class="next-image"><span>NEXT</span> <i class="fa fa-angle-right"></i></div>';
    }

    return $output;

}

add_filter( "previous_image_link", "cyb_previous_image_link", 10, 4 );
function cyb_previous_image_link( $output, $attachment_id, $size, $text ) {

    if( $output == '' ) {
        return '<div class="previous-image"><span>PREV</span> <i class="fa fa-angle-right"></i></div>';
    }

    return $output;

}
  • Thanks. I didn't know there's a function like that. Let me try it out and see if it will solve the problem. – vanduzled Nov 18 '15 at 9:10

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.