Make WordPress Core

Opened 13 years ago

Closed 10 years ago

#19904 closed enhancement (fixed)

Trim Leading and Trailing White Space in a Post Title

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

Description

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

trim($post_title);

Attachments (2)

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

Download all attachments as: .zip

Change History (9)

#1 @greenspeakmedia
13 years ago

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

#2 @jane
13 years ago

Yes, please.

#3 @nacin
13 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
11 years ago

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

#5 @nikolov.tmw
10 years 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.

@iseulde
10 years ago

#6 @iseulde
10 years 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
10 years ago

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

[29801] was a thing.

Note: See TracTickets for help on using tickets.