• 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 ^^’

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘[Suggestion] numeric values in post slug’ is closed to new replies.