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

Attachment file content cannot be saved

…collation is the “Options” column. Here the table uses the utf8_general_ci collation, which is a utf8 collation and needs to be changed. Change the collation to a matching utf8mb4 collation, which in this case is utf8mb4_general_ci and save the database table: The collation of the meta_key field does not matter….

Ultimate FAQs
Ultimate FAQs is a FAQ plugin that can create FAQs. It has a search, and enabling Relevanssi may break that…
GDPR Compliance

We have a privacy policy that covers your use of this web site and our customer data use. However, if you’re interested in how using Relevanssi affects the GDPR compliance of your own site, here we have answers for you. In general, Relevanssi doesn’t store any information about users and…

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