WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

If you use the [gallery] tag at all you know that permalinks for image attachments end up like blog.com/2011/03/18/post-permalink/attachment-permalink.

The URL extension from the post permalink appears to be based on the attachment's title on first save. To my knowledge, however, this permalink does not update when the image title is edited in the media tools. I cannot find a way to do edit attachment permalinks at all, actually.

Is there a user-facing interface I'm missing that will let users edit an attachment's permalink?

share|improve this question
up vote 9 down vote accepted

This'll add a slug field to the edit attachment page, which'll allow you to independently change it when and how you choose to.

Drop it into a plugin or your theme's functions.php;

function wpse_12405_edit_attachment_name( $fields, $post ) {
    $fields['post_name'] = array(
        'label' => __( 'Slug' ),
        'value' => $post->post_name,

    return $fields;

add_filter( 'attachment_fields_to_edit', 'wpse_12405_edit_attachment_name', 10, 2 );

function wpse_12405_save_attachment_name( $attachment, $POST_data ) {
    if ( ! empty( $POST_data['post_name'] ) )
        $attachment['post_name'] = $POST_data['post_name'];

    return $attachment;

add_filter( 'attachment_fields_to_save', 'wpse_12405_save_attachment_name', 10, 2);
share|improve this answer

There is a plugin Rename Media that changes the filename when you edit the title.

share|improve this answer

The solution of TheDeadMedic works fine, but I would recommend adding sanitize_title() in saving filter to make sure that the value is always a valid slug:

function __save_attachment_name( $attachment, $POST_data )
    if ( !empty( $POST_data['post_name'] ) )
        $attachment['post_name'] = sanitize_title( $POST_data['post_name'] );
    return $attachment;
add_filter( 'attachment_fields_to_save', '__save_attachment_name', 10, 2);
share|improve this answer
No need, WordPress will do the heavy lifting when $attachment is passed through wp_update_post() – TheDeadMedic Oct 6 '15 at 20:24

WordPress stores the original filename in the database as a unique identifier for the attachment. Unfortunately, as far as I know, there isn't any way of changing it within the UI. It's not super convenient, but you'd most likely have to re-upload the file.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.