using Revelanssi plugin. also using Divi Theme which includes the Divi Builder.
When I search on my site, excerpts include something like, 'Home / You searched for: "search term"' on the search results page. It took me awhile to figure out they were coming from the page content itself.
I was using the Yoast shortcode [wpseo_breadcrumbs] to display very nice-looking breadcrumb trails on my pages in WordPress. But it's really awkward to see that showing up in search results!
Incidentally, I'm also using the Divi Theme, which includes the Divi Builder, by Elegant Themes. I'm also using Relevanssi plugin, so that throws another monkey wrench into the mix.
In Revelanssi Settings, show shortcode content normally: Settings -> Revelanssi -> Indexing -> Expand shortcodes: CHECK.
In Divi Theme Options, grab real excerpts so that Relevanssi search results page works correctly: Divi -> Theme Options -> Use excerpts when defined -> ENABLED. Skip this step if not using Divi. This suggestion is given by Relevanssi.
In your child theme, remove Yoast SEO breadcrumbs in excerpts in your search results page.
Add the code below to your child theme's functions.php
file.
In your child theme, modify the Search Results page to grab the excerpt, rather than truncate the post content.
Add or replace your child theme's index.php
file below.
Modify this step if not using Divi. Look for "search" in the code to see what is affecting the search results page.
I added a page title, info about the search term used, and URLs for each page similar to Google search results.
//* Remove Yoast SEO breadcrumbs from Revelanssi's search results
add_filter( 'the_content', 'wpdocs_remove_shortcode_from_index' );
function wpdocs_remove_shortcode_from_index( $content ) {
if ( is_search() ) {
$content = strip_shortcodes( $content );
}
return $content;
}
<?php // Copied this file from Divi theme to affect search results page ?>
<?php get_header(); ?>
<div id="main-content">
<div class="container">
<div id="content-area" class="clearfix">
<div id="left-area">
<!-- START EDIT SEARCH RESULTS PAGE -->
<?php if( is_search() ) { ?>
<h1 class="search-title">Search Results</h1>
<p class="search-query">You searched for: <?php echo get_search_query(); ?></p>
<?php } ?>
<!-- END EDIT SEARCH RESULTS PAGE -->
<?php
if ( have_posts() ) :
while ( have_posts() ) : the_post();
$post_format = et_pb_post_format(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class( 'et_pb_post' ); ?>>
<?php
$thumb = '';
$width = (int) apply_filters( 'et_pb_index_blog_image_width', 1080 );
$height = (int) apply_filters( 'et_pb_index_blog_image_height', 675 );
$classtext = 'et_pb_post_main_image';
$titletext = get_the_title();
$thumbnail = get_thumbnail( $width, $height, $classtext, $titletext, $titletext, false, 'Blogimage' );
$thumb = $thumbnail["thumb"];
et_divi_post_format_content();
if ( ! in_array( $post_format, array( 'link', 'audio', 'quote' ) ) ) {
if ( 'video' === $post_format && false !== ( $first_video = et_get_first_video() ) ) :
printf(
'<div class="et_main_video_container">
%1$s
</div>',
$first_video
);
elseif ( ! in_array( $post_format, array( 'gallery' ) ) && 'on' === et_get_option( 'divi_thumbnails_index', 'on' ) && '' !== $thumb ) : ?>
<!-- START EDIT SEARCH RESULTS PAGE -->
<?php if( is_search() ) { ?>
<?php if ( has_post_thumbnail() ) { ?>
<a class="search-featured-image" href="<?php the_permalink(); ?>">
<?php echo get_the_post_thumbnail( $post->ID, 'thumbnail' ); ?>
</a>
<?php } ?>
<!-- END EDIT SEARCH RESULTS PAGE -->
<?php } else { ?>
<a class="entry-featured-image-url" href="<?php the_permalink(); ?>">
<?php print_thumbnail( $thumb, $thumbnail["use_timthumb"], $titletext, $width, $height ); ?>
</a>
<?php } ?>
<?php
elseif ( 'gallery' === $post_format ) :
et_pb_gallery_images();
endif;
} ?>
<?php if ( ! in_array( $post_format, array( 'link', 'audio', 'quote' ) ) ) : ?>
<?php if ( ! in_array( $post_format, array( 'link', 'audio' ) ) ) : ?>
<h2 class="entry-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<!-- START EDIT SEARCH RESULTS PAGE -->
<?php if( is_search() ) { ?>
<div class="permalink"><a href="<?php the_permalink(); ?>"><?php the_permalink(); ?></a></div>
<?php } ?>
<!-- END EDIT SEARCH RESULTS PAGE -->
<?php endif; ?>
<?php
et_divi_post_meta();
if ( 'on' !== et_get_option( 'divi_blog_style', 'false' ) || ( is_search() && ( 'on' === get_post_meta( get_the_ID(), '_et_pb_use_builder', true ) ) ) ) {
truncate_post( 270 );
} else {
the_content();
}
?>
<?php endif; ?>
</article> <!-- .et_pb_post -->
<?php
endwhile;
if ( function_exists( 'wp_pagenavi' ) )
wp_pagenavi();
else
get_template_part( 'includes/navigation', 'index' );
else :
get_template_part( 'includes/no-results', 'index' );
endif;
?>
</div> <!-- #left-area -->
<?php if( ! is_search() ) {
get_sidebar();
} ?>
</div> <!-- #content-area -->
</div> <!-- .container -->
</div> <!-- #main-content -->
<?php
get_footer();