Skip to content

Instantly share code, notes, and snippets.

@searchwpgists
Created October 9, 2024 15:35
Show Gist options
  • Select an option

  • Save searchwpgists/35a7cdd8df9eeb39787f9170ce46d650 to your computer and use it in GitHub Desktop.

Select an option

Save searchwpgists/35a7cdd8df9eeb39787f9170ce46d650 to your computer and use it in GitHub Desktop.
Index post content built with the Elementor Builder
<?php
// Index post content built with the Elementor Builder
add_filter( 'searchwp\source\post\attributes\content', function( $content, $args ) {
if ( class_exists('\Elementor\Plugin' ) ) {
// We don't want CSS code on the post content while indexing.
add_filter( 'elementor/frontend/builder_content/before_print_css', '__return_false' );
$elementor = new \Elementor\Frontend();
$content = $elementor->get_builder_content_for_display( $args['post']->ID );
// Remove the filter once we have grabbed the content.
remove_filter( 'elementor/frontend/builder_content/before_print_css', '__return_false' );
}
return $content;
}, 20, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment