Filter
uncanny-automator
automator_get_the_excerpt_separator
Filters the separator used to join multiple excerpts within the Automator.
add_filter( 'automator_get_the_excerpt_separator', $callback, 10, 1 );
Description
Filters the separator used to split the content into an excerpt. Developers can modify this separator to customize how excerpts are generated from post content when no custom excerpt is present.
Usage
add_filter( 'automator_get_the_excerpt_separator', 'your_function_name', 10, 1 );
Return Value
The filtered value.
Examples
<?php
/**
* Example: Change the default separator used when creating an excerpt from post content.
*
* By default, the excerpt is split into words using a space (' ') as a separator.
* This example changes the separator to a comma and a space (', ') to create an
* excerpt that splits sentences rather than just words.
*
* @param string $separator The current separator character(s).
* @return string The new separator character(s).
*/
add_filter( 'automator_get_the_excerpt_separator', 'my_automator_custom_excerpt_separator', 10, 1 );
function my_automator_custom_excerpt_separator( $separator ) {
// Change the default space separator to a comma and space.
return ', ';
}
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/core/lib/utilities/class-automator-utilities.php:748
public function automator_get_the_excerpt( $post_id, $length = 25 ) {
$post = get_post( $post_id );
if ( ! $post instanceof WP_Post ) {
return '';
}
$post_content = $post->post_content;
$post_excerpt = $post->post_excerpt;
if ( ! empty( $post_excerpt ) ) {
// If custom excerpt is defined, return the same
return apply_filters( 'automator_get_the_excerpt', $post_excerpt, $post_content, $post_id, $length );
}
$length = apply_filters( 'automator_get_the_excerpt_length', $length );
$excerpt = sanitize_text_field( strip_shortcodes( wp_strip_all_tags( $post_content ) ) );
$words = explode( apply_filters( 'automator_get_the_excerpt_separator', ' ' ), $excerpt );
$len = min( $length, count( $words ) );
$excerpt = array_slice( $words, 0, $len );
$excerpt = join( ' ', $excerpt );
if ( ! empty( $excerpt ) ) {
$excerpt = $excerpt . apply_filters( 'automator_get_the_excerpt_continuity', '...', $post_id );
}
return apply_filters( 'automator_get_the_excerpt', $excerpt, $post_content, $post_id, $length );
}