Filter
uncanny-automator
automator_get_the_excerpt_continuity
Filters the excerpt continuity setting for the current post when retrieving excerpts.
add_filter( 'automator_get_the_excerpt_continuity', $callback, 10, 1 );
Description
Allows developers to modify the generated excerpt's continuity. This filter fires after the excerpt content is extracted and before it's joined back into a string. Developers can use this to alter how words are rejoined, add custom separators, or manipulate the excerpt's flow based on the post ID.
Usage
add_filter( 'automator_get_the_excerpt_continuity', 'your_function_name', 10, 1 );
Parameters
-
$post_id(mixed) - This parameter is the content of the post or page.
Return Value
The filtered value.
Examples
/**
* Filters the continuity string for the excerpt.
*
* This example adds a custom ellipsis if the excerpt is truncated and
* if the post is from a specific custom post type.
*/
add_filter(
'automator_get_the_excerpt_continuity',
function( $continuity_string, $post_id ) {
// Check if the post is from a custom post type we want to modify.
$post_type = get_post_type( $post_id );
if ( 'your_custom_post_type' === $post_type ) {
// Add a more descriptive ellipsis for this specific post type.
return ' [more...]';
}
// Otherwise, return the default continuity string.
return $continuity_string;
},
10,
2 // Accepts 2 arguments: $continuity_string, $post_id
);
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:753
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 );
}