• Showing images on WordPress search page

    When searching a blog using the twenty-twelve theme the images get commented out. It only will display an excerpt so your image is commented out. In order to fix this you must edit your CONTENT.PHP file, not your SEARCH.PHP.

    Open content.php and find the following lines:

    <?php if ( is_search() ) : // Only display Excerpts for Search ?>
    <div class=”entry-summary”>
    <?php the_excerpt(); ?>
    </div><!– .entry-summary –>
    <?php else : ?>
    <div class=”entry-content”>
    <?php the_content( __( ‘Continue reading <span class=”meta-nav”>&rarr;</span>’, ‘twentytwelve’ ) ); ?>
    <?php wp_link_pages( array( ‘before’ => ‘<div class=”page-links”>’ . __( ‘Pages:’, ‘twentytwelve’ ), ‘after’ => ‘</div>’ ) ); ?>
    </div><!– .entry-content –>
    <?php endif; ?>






    Now remove some PHP code to make it look like this:

    <div class=”entry-content”>
    <?php the_content( __( ‘Continue reading <span class=”meta-nav”>&rarr;</span>’, ‘twentytwelve’ ) ); ?>
    <?php wp_link_pages( array( ‘before’ => ‘<div class=”page-links”>’ . __( ‘Pages:’, ‘twentytwelve’ ), ‘after’ => ‘</div>’ ) ); ?>
    </div>

    Congratulations, you now will have your images in the search results. Note that this will also return all of the post content and not just excerpts.




    Share

    Leave a reply