Skip to content

Instantly share code, notes, and snippets.

@campusboy87
Last active July 12, 2017 15:23
Show Gist options
  • Save campusboy87/e2935b7117d0c7e59662bbce1481e930 to your computer and use it in GitHub Desktop.
Save campusboy87/e2935b7117d0c7e59662bbce1481e930 to your computer and use it in GitHub Desktop.
Автоматическое добавление названия изображения при выборе фотки в поле названия поста. Можно указать тип поста.
// Автодобавление названия изображения при выборе фотки в поле названия поста
add_action( 'admin_print_footer_scripts', function () {
global $current_screen;
if ( 'post' == $current_screen->post_type && 'post' == $current_screen->base ) {
?>
<script>
jQuery(document).ready(function ($) {
var $titlePostInput = $('[name=post_title]');
$(document).on('mouseenter', '.media-button-select', function () {
var titlePostText = $titlePostInput.val();
var titleImg = $('[data-setting=title] input').val();
if (!titlePostText && titleImg) {
$titlePostInput.val(titleImg).focus();
}
});
});
</script>
<?php
}
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment