wpfts_get_fulltext (Filter)
The wpfts_get_fulltext
filter in WP Fast Total Search allows developers to modify the full post text used for creating Smart Excerpts before it’s split into sentences. This provides an opportunity to perform additional text processing, such as removing unwanted characters, transforming formatting, or adding text from other sources.
When to Use
This filter can be useful if you need to:
- Clean the text of unwanted characters or HTML tags before creating Smart Excerpts.
- Add text from other post fields, such as meta fields or taxonomies, to Smart Excerpts.
- Modify the text formatting, such as replacing line breaks with spaces.
Arguments
$fulltext
(string): The full post text that will be used for creating Smart Excerpts.$post_id
(int): The ID of the post.
Return Value
$fulltext
(string): The modified full post text.
Example (Removing HTML tags from the full text)
add_filter('wpfts_get_fulltext', 'remove_html_from_fulltext', 10, 2);
function remove_html_from_fulltext($fulltext, $post_id) {
return wp_strip_all_tags( $fulltext );
}
Example (Appending text from a meta field)
add_filter('wpfts_get_fulltext', 'append_meta_to_fulltext', 10, 2);
function append_meta_to_fulltext($fulltext, $post_id)
{
$meta_value = get_post_meta($post_id, 'my_custom_field', true);
if ($meta_value) {
$fulltext .= ' ' . $meta_value;
}
return $fulltext;
}
Important Notes
- The
wpfts_get_fulltext
filter is called before the text is split into sentences. - Changes made to
$fulltext
will affect the content of Smart Excerpts.
This filter provides developers with additional control over the data used for creating Smart Excerpts in WP Fast Total Search.