Skip to main contentSkip to footer

OceanWP is a popular WordPress theme. It works fine with Relevanssi, but how it handles excerpts on the search results pages is not fully compatible with Relevanssi. Relevanssi expects the theme to use the_excerpt() to print out the excerpts. OceanWP does that, but only for posts that have hand-made excerpts. If the post doesn’t have an excerpt, OceanWP uses

echo wp_trim_words( strip_shortcodes( $post->post_content ), $length );

to print out the excerpt, and that does not show the Relevanssi excerpt.

To fix this problem, create a child theme for OceanWP if you don’t already have one. In the child theme, add file partials/search/content.php with this content:

<?php
/**
 * Search result page entry content
 *
 * @package OceanWP WordPress theme
 */

// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

global $post;

// Excerpt length.
$length = apply_filters( 'ocean_search_results_excerpt_length', '30' );

?>

<div class="search-entry-summary clr"<?php oceanwp_schema_markup( 'entry_content' ); ?>>
	<p>
		<?php
		the_excerpt();
		?>
	</p>
</div><!-- .search-entry-summary -->

Now when you enable the child theme, this will make sure OceanWP always uses the_excerpt() to print out the excerpt, and the Relevanssi-created excerpts will appear.

Highlighted titles

If you want highlights in the post titles in search results, add partials/search/header.php to your child theme with this content:

<?php
/**
 * Search result page entry header
 *
 * @package OceanWP WordPress theme
 */

// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

?>

<header class="search-entry-header clr">
	<h2 class="search-entry-title entry-title">
		<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" rel="bookmark"><?php function_exists( 'relevanssi_the_title' ) ? relevanssi_the_title() : the_title(); ?></a>
	</h2>
</header>

This template uses the relevanssi_the_title() function to print out the title to make sure the highlights are included.

Multisite searching

If you want to use multisite searching with OceanWP, it’s easiest to make the template changes by replacing the file partials/search/layout.php in the child theme with this:

<?php
/**
 * Search result page entry layout
 *
 * @package OceanWP WordPress theme
 */

// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

if ( isset( $post->blog_id ) ) {
	switch_to_blog( $post->blog_id );
}

?>

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

	<div class="search-entry-inner clr">

		<?php
		// Featured Image.
		get_template_part( 'partials/search/thumbnail' );
		?>

		<div class="search-entry-content clr">

			<?php
			// Title.
			get_template_part( 'partials/search/header' );

			// Content.
			get_template_part( 'partials/search/content' );

			// Read more button.
			get_template_part( 'partials/search/readmore' );

			?>

		</div><!-- .search-entry-content -->

	</div><!-- .search-entry-inner -->

</article><!-- #post-## -->

<?
if ( isset( $post->blog_id ) ) {
	restore_current_blog();
}

Your account

Not logged in. Log in to see your license details.

Search

Popular Resources

Yoast SEO

Starting from versions 2.4.0 (Premium) and 4.3.0 (Free), Relevanssi doesn’t index posts that have been marked “noindex” in the Yoast SEO settings (“Allow search engines to show this Post in search results?”). If the “noindex” setting is in the default value or set to explicit “yes”, Relevanssi indexes the post….

Oxygen and Ninja Tables
Relevanssi has support both for Oxygen and Ninja Tables, but the way the Ninja Tables support is done, it’s not…

Related Posts:

Comment Section:

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed