Filter
uncanny-automator-pro
automator_pro_formatter_title_case_ignore
Filters the list of words to ignore when converting text to title case.
add_filter( 'automator_pro_formatter_title_case_ignore', $callback, 10, 1 );
Description
Filters the list of words to ignore when applying title case formatting. Developers can add or remove words from this array to customize which words remain lowercase in titles, ensuring grammatical correctness for specific cases. This hook fires within the `format_title` method of the text formatter.
Usage
add_filter( 'automator_pro_formatter_title_case_ignore', 'your_function_name', 10, 1 );
Return Value
The filtered value.
Examples
/**
* Add custom words to the title case ignore list.
*
* This function adds a few more common words to the default list of words
* that should not be capitalized in title case.
*
* @param array $ignore_words The default array of words to ignore.
* @return array The modified array of words to ignore.
*/
add_filter(
'automator_pro_formatter_title_case_ignore',
function( $ignore_words ) {
// Add some less common prepositions and conjunctions to the ignore list.
$custom_ignore = array(
'upon',
'towards',
'without',
'because',
'so',
'yet',
);
// Merge the custom words with the existing ignore list.
return array_merge( $ignore_words, $custom_ignore );
},
10, // Priority: 10 is the default, so this is standard.
1 // Accepted args: The filter callback accepts only one argument.
);
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
uncanny-automator-pro/src/integrations/formatter/actions/text-formatter.php:243
public function format_title( $input ) {
$ignore = apply_filters(
'automator_pro_formatter_title_case_ignore',
array(
'of',
'a',
'the',
'and',
'an',
'or',
'nor',
'but',
'is',
'if',
'then',
'else',
'when',
'at',
'from',
'by',
'on',
'off',
'for',
'in',
'out',
'over',
'to',
'into',
'with',
)
);
$words = explode( ' ', $input );
foreach ( $words as &$word ) {
if ( ! in_array( strtolower( $word ), $ignore, true ) ) {
$word = ucwords( $word );
} else {
$word = strtolower( $word );
}
}
return implode( ' ', $words );
}