Created
November 28, 2016 14:19
-
-
Save tagmetag/8bb4c988eba48fcbff679e2ef32ed825 to your computer and use it in GitHub Desktop.
Create field to edit slug on Attachment Page WordPress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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