Prevent WordPress from abbreviating-long-slugs…-in-the-admin

There is a filter at the end of the function: 'get_sample_permalink_html'. Hook into this and just replace the shortened form with the full length.

<?php # -*- coding: utf-8 -*-
/* Plugin Name: T5 Unabridge Permalink Slug */

add_filter( 'get_sample_permalink_html', 't5_unabridge_sample_permalink', 10, 2 );

/**
 * Replaces the shortened permalink with its full form.
 *
 * @param  string $sample Permalink HTML
 * @param  int    $id Post ID
 * @return string
 */
function t5_unabridge_sample_permalink( $sample, $id )
{
    $link = get_sample_permalink( $id );
    $s1   = '<span id="editable-post-name" ';
    $s2   = '</span>';

    return preg_replace(
        '~' . $s1 . '([^>]*)>([^<]*)' . $s2 . '~Ui',
        $s1 . '$1>' . $link[1] . $s2,
        $sample
    );
}

Result

Post title: This is a rather long post title. WordPress would shorten it by default, but our nice plugin prevents that.

enter image description here

Download from GitHub.

Leave a Comment