Skip to content

Instantly share code, notes, and snippets.

@macgraphic
Last active October 26, 2017 15:29
Show Gist options
  • Save macgraphic/4ef1fa16934d817e22195cc54d645ae3 to your computer and use it in GitHub Desktop.
Save macgraphic/4ef1fa16934d817e22195cc54d645ae3 to your computer and use it in GitHub Desktop.
Show or hide the featured image thumb if post has gallery
<?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