WordPress.org

Make WordPress Core

Opened 4 years ago

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

Download all attachments as: .zip

Change History (9)

comment:1 @greenspeakmedia4 years ago

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

comment:2 @jane4 years ago

Yes, please.

comment:3 @nacin4 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 @wonderboymusic14 months ago

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

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

@iseulde11 months ago

comment:6 @iseulde11 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 @wonderboymusic11 months ago

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

[29801] was a thing.

Note: See TracTickets for help on using tickets.