Last active
October 26, 2017 15:29
-
-
Save macgraphic/4ef1fa16934d817e22195cc54d645ae3 to your computer and use it in GitHub Desktop.
Show or hide the featured image thumb if post has gallery
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// if the post does NOT have a [gallery], show the featured image | |
if ( strpos( $post->post_content,'[gallery' ) === false ) { | |
$gallery = 0; | |
if ( has_post_thumbnail() && 'gallery' != get_post_format() ) { | |
$large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'large' ); | |
if ( ! empty( $large_image_url[0] ) ) { | |
echo '<a rel="lightbox" href="' . esc_url( $large_image_url[0] ) . '" title="' . the_title_attribute( array( 'echo' => 0 ) ) . '">'; | |
echo get_the_post_thumbnail( $post->ID, 'thumbnail', array( 'class' => 'float-right thumbnail' ) ); | |
echo '</a>'; | |
} | |
} | |
} else { | |
$gallery = 1; | |
// Yes, there's a gallery so don't call in the featured image. simples. | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment