Skip to content

Instantly share code, notes, and snippets.

@tagmetag
Created November 28, 2016 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tagmetag/8bb4c988eba48fcbff679e2ef32ed825 to your computer and use it in GitHub Desktop.
Save tagmetag/8bb4c988eba48fcbff679e2ef32ed825 to your computer and use it in GitHub Desktop.
Create field to edit slug on Attachment Page WordPress
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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment