how to filter post titles

Posted on 01 January 2010 at 4:46 PM (2 months, 1 week ago) | Filed under code

If you know that you will want to apply a filter to all of your post titles in WordPress, such as forcing uppercase, lowercase, or title capitalization, you can use a filter to do so. The filter below will force a title to lowercase as the post is saved:

  1. if ( !function_exists( 'ucc_post_title_filter' ) ) :
  2. function
  3. ucc_post_title_filter( $data ) {
  4.   $title = $data['post_title'];
  5.  
  6.   $title = strtolower( $title );
  7.   $data['post_title'] = $title;
  8.  
  9.   return( $data );
  10. }
  11. add_filter( 'wp_insert_post_data' , 'ucc_post_title_filter' );
  12. endif;

On line 6, strtolower() can be exchanged for any text-transforming function.

Reply

* = required
** = will not be published

This entry was written 2 months, 1 week ago. You may want to use the search function for a more recent entry on this topic.

Copyright © 2003-2010 J.M. Dodd. | XHTML 1.0 Strict | CSS | RSS | 508