Created
August 24, 2020 21:57
-
-
Save seojacky/649b0067e5a104f3cd18e69078d41a63 to your computer and use it in GitHub Desktop.
This file contains 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
//ВАРИАНТ №1 | |
//автозаполнение полей при вставке медиафайлов start | |
function wph_auto_alt_title_caption($attachment_ID) { | |
$filename = $_REQUEST['name']; | |
$withoutExt = preg_replace('/\\.[^.\\s]{3,4}$/', '', $filename); | |
$withoutExt = str_replace(array('-','_'), ' ', $withoutExt); | |
/* Автозаполнение подписи и описания - мне не пригодилось | |
$my_post = array( | |
'ID' => $attachment_ID, | |
'post_excerpt' => $withoutExt, //подпись | |
'post_content' => $withoutExt, //описание | |
); | |
wp_update_post($my_post); | |
*/ | |
//атрибут alt | |
update_post_meta($attachment_ID, '_wp_attachment_image_alt', $withoutExt); | |
} | |
add_action('add_attachment', 'wph_auto_alt_title_caption'); | |
//автозаполнение полей при вставке медиафайлов end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment