Manual excerpts for pages not working on Search

Image says it all… Page Edit:

enter image description here

Search Results:

enter image description here

functions.php to enable page excerpts

add_post_type_support( 'page', 'excerpt' );

search.php code for displaying excerpt

<?php the_excerpt(); ?>
<!-- tried <?php echo get_the_excerpt();?> too -->

Full search.php code

<?php
/**
 * The template for displaying Search Results pages.
 *
 * @package Shape
 * @since Shape 1.0
 */

get_header(); 
get_template_part('inc/header-image');?>


<div class="wrapper">
    <div class="container main">
        <div class="post-area grid_9">
            <div class="posts-container">
                <header class="page-header">
                    <h1 class="page-title"><?php printf( __( 'Resultados da Busca' ), '<span>' . get_search_query() . '</span>' ); ?></h1>
                    <input type="search" value="<?php printf( __( '%s' ), '' . get_search_query() . '' ); ?>"></input>
                </header><!-- .page-header -->
                <div class="linha-horizontal"></div>
                <?php while (have_posts()) : the_post(); ?>
                    <div class="post-entry clearfix"> <!-- Main wrapper -->
                        <div class="post-entry-content"> <!-- Post-entry-content -->
                                <h2><a class="search-item-title" href="https://wordpress.stackexchange.com/questions/120229/<?php the_permalink(" ') ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
                                        <?php the_excerpt(); ?>
                                        <a href="https://wordpress.stackexchange.com/questions/120229/<?php the_permalink(" ') ?>" class="post-entry-read-more" title="<?php the_title(); ?>"><?php the_permalink(' ') ?></a>
                                        <div class="linha-horizontal search-divider"></div>
                        </div><!-- END of post-entry-content -->
                    </div><!--End of main wrapper -->
                    <?php endwhile; ?>

            </div>
        </div>
    </div>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>

1 Answer
1

You’re confusing “post type support” – which means enabling “feature” (and therefore MetaBoxes) for a post – with templating.

  1. Go into your theme, search for the search.php template in the folder.
  2. Add a Child Theme
  3. Add a file named search.php to your Child theme and copy/paste the content of your parent themes template file in there.
  4. Exchange the_content() with the_excerpt()

Keep in mind that this can highly differ from theme to theme. Some themes use “Template Parts” to add parts to build a template. Others use “Conditional Tags” to switch between parts in their code in fallback template files of the “Template Hierarchy” and others use filters or hooks to alter the output in a template.

Note: This answer is meant as a guide, not a copy/paste solution as the solution can highly differ from theme to theme.

Leave a Comment