Skip to content

Instantly share code, notes, and snippets.

View allan23's full-sized avatar

Allan Collins allan23

View GitHub Profile
@allan23
allan23 / noindex-ep-yoast.php
Created June 20, 2019 16:55
Prevent Elasticsearch indexing when post is set to noindex in Yoast SEO.
<?php
use ElasticPress\Indexables as Indexables;
add_filter( 'ep_post_sync_args_post_prepare_meta', function ( $post_args, $post_id ) {
$noindex = get_post_meta( $post_id, '_yoast_wpseo_meta-robots-noindex', true );
if ( 1 === absint( $noindex ) ) {
Indexables::factory()->get( 'post' )->delete( $post_id, false );
return false;
<?php
/**
* Generate excerpt from returned content from ElasticPress.
*/
function ep_excerpt( $excerpt ) {
global $post;
if ( ! isset( $post->elasticsearch ) ) {
return $excerpt;
}
$excerpt_length = apply_filters( 'excerpt_length', 55 );