Page begins with number, WordPress adds 2

Within the wp_unique_post_slug function, checks are made to “Prevent new post slugs that could result in URLs that conflict with date archives.” Here’s the relevant code from line 3812 from wp-includes/post.php

    // Prevent new post slugs that could result in URLs that conflict with date archives.
    $post = get_post( $post_ID );
    $conflicts_with_date_archive = false;
    if ( 'post' === $post_type && ( ! $post || $post->post_name !== $slug ) && preg_match( '/^[0-9]+$/', $slug ) && $slug_num = intval( $slug ) ) {
        $permastructs   = array_values( array_filter( explode( "https://wordpress.stackexchange.com/", get_option( 'permalink_structure' ) ) ) );
        $postname_index = array_search( '%postname%', $permastructs );

        /*
         * Potential date clashes are as follows:
         *
         * - Any integer in the first permastruct position could be a year.
         * - An integer between 1 and 12 that follows 'year' conflicts with 'monthnum'.
         * - An integer between 1 and 31 that follows 'monthnum' conflicts with 'day'.
         */
        if ( 0 === $postname_index ||
            ( $postname_index && '%year%' === $permastructs[ $postname_index - 1 ] && 13 > $slug_num ) ||
            ( $postname_index && '%monthnum%' === $permastructs[ $postname_index - 1 ] && 32 > $slug_num )
        ) {
            $conflicts_with_date_archive = true;
        }
    }

Leave a Comment