WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 7 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:

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 7 months ago.
19904.patch (660 bytes) - added by iseulde 7 months ago.

Download all attachments as: .zip

Change History (9)

comment:1 @greenspeakmedia3 years ago

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

comment:2 @jane3 years ago

Yes, please.

comment:3 @nacin3 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' );

comment:4 @wonderboymusic10 months ago

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

comment:5 @nikolov.tmw7 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.

@iseulde7 months ago

comment:6 @iseulde7 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.

comment:7 @wonderboymusic7 months ago

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

[29801] was a thing.

Note: See TracTickets for help on using tickets.