Нам нужно wp_enqueue_script скрипт и wp_enqueue_style стиль с add_action в файл functions.php. Просто включите файл jQuery и файл таблицы стилей в этот скрипт.
// Register Scripts & Styles in Admin panel
function custom_color_picker_scripts() {
wp_enqueue_style( 'wp-color-picker' );
wp_enqueue_script( 'iris', admin_url( 'js/iris.min.js' ), array( 'jquery-ui-draggable', 'jquery-ui-slider', 'jquery-touch-punch' ), false, 1 );
wp_enqueue_script( 'cp-active', plugins_url('/js/cp-active.js', __FILE__), array('jquery'), '', true );
}
add_action( 'admin_enqueue_scripts', custom_color_picker_scripts);
Теперь создайте новый файл javascript, например, cp-active.js, и сохраните его в пути к файлу, определенному как «/js/cp-active.js», используя код сильфона.
jQuery('.color-picker').iris({
// or in the data-default-color attribute on the input
defaultColor: true,
// a callback to fire whenever the color changes to a valid color
change: function(event, ui){},
// a callback to fire when the input is emptied or an invalid color
clear: function() {},
// hide the color picker controls on load
hide: true,
// show a group of common colors beneath the square
palettes: true
});
Добавьте текстовое поле на страницу настроек с классом CSS для палитры цветов, где вы хотите отображать вводимый текст. Я использовал «color_code» для ввода переменной $.
<input id="color_code" class="color-picker" name="color_code" type="text" value="" />
Дополнительные сведения см. в разделе Добавление темы или плагина WordPress для выбора цвета jQuery
person
csehasib
schedule
25.02.2015