post_excerpt, unless the post is * protected. Only works in the Loop. * * @global $post The global post object. */ function relevanssi_the_excerpt() { global $post; if ( ! post_password_required( $post ) ) { echo '

' . $post->post_excerpt . '

'; // WPCS: XSS ok. } else { esc_html_e( 'There is no excerpt because this is a protected post.', 'relevanssi' ); } } /** * Generates an excerpt for a post. * * @global $post The global post object. * * @param object $t_post The post object. * @param string $query The search query. * * @return string The created excerpt. */ function relevanssi_do_excerpt( $t_post, $query ) { global $post; // Back up the global post object, and replace it with the post we're working on. $old_global_post = null; if ( null !== $post ) { $old_global_post = $post; } $post = $t_post; // WPCS: override ok, must do because shortcodes etc. expect it. $remove_stopwords = true; /** * Filters the search query before excerpt-building. * * Allows filtering the search query before generating an excerpt. This can * useful if you modifications to the search query, and it may help when working * with stemming. * * @param string $query The search query. */ $query = apply_filters( 'relevanssi_excerpt_query', $query ); // Minimum word length is -1, we don't care about it right now. $terms = relevanssi_tokenize( $query, $remove_stopwords, -1 ); // These shortcodes cause problems with Relevanssi excerpts. $problem_shortcodes = array( 'layerslider', 'responsive-flipbook', 'breadcrumb', 'robogallery', 'gravityview', 'wp_show_posts' ); /** * Filters the excerpt-building problem shortcodes. * * Some shortcodes cause problems in Relevanssi excerpt-building. These * shortcodes are disabled before building the excerpt. This filter allows * modifying the list of shortcodes. * * @param array $problem_shortcodes Array of problematic shortcode names. */ $problem_shortcodes = apply_filters( 'relevanssi_disable_shortcodes_excerpt', $problem_shortcodes ); foreach ( $problem_shortcodes as $shortcode ) { remove_shortcode( $shortcode ); } /** * Filters the post content before 'the_content'. * * Filters the post content in excerpt building process before 'the_content' * filter is applied. * * @param string $content The post content. * @param object $post The post object. * @param string $query The search query. */ $content = apply_filters( 'relevanssi_pre_excerpt_content', $post->post_content, $post, $query ); // Add the custom field content. if ( 'on' === get_option( 'relevanssi_excerpt_custom_fields' ) ) { $content .= relevanssi_get_custom_field_content( $post->ID ); } // Autoembed discovery can really slow down excerpt-building. relevanssi_kill_autoembed(); // This will print out the attachment file name in front of the excerpt, and we // don't want that. remove_filter( 'the_content', 'prepend_attachment' ); /** This filter is documented in wp-includes/post-template.php */ $content = apply_filters( 'the_content', $content ); /** * Filters the post content after 'the_content'. * * Filters the post content in excerpt building process after 'the_content' * filter is applied. * * @param string $content The post content. * @param object $post The post object. * @param string $query The search query. */ $content = apply_filters( 'relevanssi_excerpt_content', $content, $post, $query ); // Removes