Handling display of title when none exists
-
The test suite for theme development contains a post with no title, but I haven’t seen any write-up on how to properly handle it. For the benefit of the community, here is how to do it using the ‘the_title’ filter:
add_filter('the_title','has_title'); function has_title($title){ if($title == ''){ return '[No Title]'; }else{ return $title; } }
When creating the function assign the incoming content to a variable, test the variable, and then either pass back the same content that came in, or a default title of some sort. Quick and simple.
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Handling display of title when none exists’ is closed to new replies.