Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- add_filter( 'the_title', 'my_capitalize_title', 10, 2 );
- function my_capitalize_title( $title, $id ) {
- // get separate words
- $words = preg_split( '/[^w]*([s]+[^w]*|$)/', $title, NULL, PREG_SPLIT_NO_EMPTY );
- $stop_words = array(
- 'the', //
- 'a',
- 'and',
- 'of',
- );
- $title_case = '';
- foreach( $words as $word ) {
- // concatenate stop word intact
- if ( in_array( $word, $stop_words ) ) {
- $title_case .= $word;
- }
- // or concatenate capitalized word
- $title_case .= ucfirst( $word );
- }
- return $title_case;
- }
Add Comment
Please, Sign In to add comment