WordPress.org

Ready to get started?Download WordPress

Forums

[Suggestion] numeric values in post slug (2 posts)

  1. hvianna
    Member
    Posted 6 years ago #

    I noticed the function used to generate the slugs (and clean up filenames) removes periods and commas, and that can be a little confusing if you have numeric values in your post title. For example, a title containing "3.5 million people" would become "35-million-people" in the slug.

    To avoid this, I just added a single line in wp-includes/formatting.php. Inside function sanitize_title_with_dashes around line 360 - find the line that reads:

    $title = strtolower($title);

    and just add before it:

    $title = preg_replace('/(\d+)(,|\.)(\d+)/','$1-$3',$title);

    This way, periods and commas, only when between two or more digits, will be replaced by a dash. In the previous example, the generated slug would now be "3-5-million-people". Still confusing, but less misleading I think.

    The ideal solution in these situations would be keeping the period (or comma), but since I wasn't sure whether that would affect any behavior of WP, I decided to keep it safe :)

    Anyway, just thought of sharing this with the community. Perhaps a better solution will arise. Sorry about my english ^^'

  2. Roger Theriault
    Member
    Posted 6 years ago #

    Better would be to generate something like 3point5-million.

Topic Closed

This topic has been closed to new replies.

About this Topic