Make WordPress Core

Opened 4 years ago

Closed 14 months ago

#19904 closed enhancement (fixed)

Trim Leading and Trailing White Space in a Post Title

Reported by: greenspeakmedia Owned by:
Milestone: 4.1 Priority: normal
Severity: normal Version: 3.3.1
Component: Posts, Post Types Keywords: has-patch
Focuses: Cc:


In working with clients today I realized that they were copying and pasting post titles but including a leading space in it by accident. Because of this the orderby feature of the query wasn't appearing to work. Turns out it was but the spaces where all correct so it was messing with the query.

I think it would make sense that on a title field of a post/ page that any leading whitespaces and any trailing white spaces should be trimmed off.

something like


Attachments (2)

default-filters.php.diff (612 bytes) - added by nikolov.tmw 14 months ago.
19904.patch (660 bytes) - added by iseulde 14 months ago.

Download all attachments as: .zip

Change History (9)

#1 @greenspeakmedia
4 years ago

The trim of this should be on save. That way it goes into the db correctly without the spaces.

#2 @jane
4 years ago

Yes, please.

#3 @nacin
4 years ago

We already do this on display, so one of the few places you would indeed see this is ordering.

This would handle it: add_filter( 'trim', 'title_save_pre' );

#4 @wonderboymusic
17 months ago

  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to Future Release

#5 @nikolov.tmw
14 months ago

  • Keywords has-patch added; needs-patch removed

The attached patch works as expected, removing any whitespace at the beginning and end of post titles.

14 months ago

#6 @iseulde
14 months ago

  • Component changed from General to Posts, Post Types
  • Milestone changed from Future Release to 4.1
  • Type changed from feature request to enhancement

Refreshed the patch. I had trouble applying it. Probably not exported from the root dir.

#7 @wonderboymusic
14 months ago

  • Resolution set to fixed
  • Status changed from new to closed

[29801] was a thing.

Note: See TracTickets for help on using tickets.