include 'if function exists' in an existing if statement

2 Replies ·

  1. existing code:-

    <?php if ( is_archive() || is_search() ) : // Only display excerpts for archives and search. ?>
                <div class="entry-summary">
                    <?php the_excerpt(); ?>
                </div><!-- .entry-summary -->
    <?php else : ?>
    stuff not changed           
    <?php endif; ?>
    

    I’ve tried the following:-

    <?php if ( is_archive() || is_search() ) && ( function_exists( 'get_the_image' ) ) : // Only display excerpts for archives and search. ?>
    
                <div class="entry-summary">
                    <?php get_the_image( array( size' => 'thumbnail', 'image_class' => 'archiveimagealignleft' ) ); ?>
                    <?php the_excerpt(); ?>
                </div><!-- .entry-summary -->
    
    <?php else : ?>
    stuff not changed           
    <?php endif; ?>
    

    to include the check that the plugin is still in use, but it gives an error

    thanks

  2. Justin Tadlock

    You’ve got some missing ( and ) in the conditional check and a missing ' before size' in your get_the_image() call.

    This should fix it:

    <?php if ( ( is_archive() || is_search() ) && ( function_exists( 'get_the_image' ) ) ) : // Only display excerpts for archives and search. ?>
    
                <div class="entry-summary">
                    <?php get_the_image( array( 'size' => 'thumbnail', 'image_class' => 'archiveimagealignleft' ) ); ?>
                    <?php the_excerpt(); ?>
                </div><!-- .entry-summary -->
    
    <?php else : ?>
    stuff not changed           
    <?php endif; ?>