Edit: icon-picker.php
<?php if (class_exists('WP_Customize_Control')) { class WP_Customize_Icon_Picker_Control extends WP_Customize_Control { public $type = 'icon_picker'; public function render_content() { $icons = [ 'dashicons-arrow-up', 'dashicons-arrow-up-alt', 'dashicons-arrow-up-alt2', 'dashicons-arrow-down-alt2', 'dashicons-arrow-left-alt2', 'dashicons-arrow-right-alt2', 'dashicons-upload', 'dashicons-arrow-up-duplicate', 'dashicons-sort', 'dashicons-thumbs-up', 'dashicons-plus', 'dashicons-plus-alt', 'dashicons-plus-alt2', 'dashicons-airplane', 'dashicons-chart-line', 'dashicons-controls-back', 'dashicons-controls-forward', 'dashicons-controls-play', 'dashicons-controls-skipback', 'dashicons-controls-skipforward', 'dashicons-controls-volumeoff', 'dashicons-controls-volumeon', 'dashicons-image-flip-vertical', 'dashicons-image-rotate', 'dashicons-image-rotate-left', 'dashicons-image-rotate-right', 'dashicons-paperclip', 'dashicons-performance', 'dashicons-share', 'dashicons-share-alt', 'dashicons-share-alt2', 'dashicons-star-filled', 'dashicons-star-half', 'dashicons-star-empty', 'dashicons-tickets-alt', 'dashicons-yes', 'dashicons-yes-alt', 'dashicons-marker', 'dashicons-clock', 'dashicons-cart', 'dashicons-shield', 'dashicons-heart', 'dashicons-megaphone', 'dashicons-location', 'dashicons-location-alt', 'dashicons-admin-home', 'dashicons-admin-collapse', 'dashicons-filter', 'dashicons-admin-customizer', 'dashicons-admin-generic', 'dashicons-admin-settings', 'dashicons-admin-tools', 'dashicons-admin-appearance', 'dashicons-external', 'dashicons-update', 'dashicons-update-alt', 'dashicons-flag', 'dashicons-hammer', 'dashicons-lightbulb', 'dashicons-awards', 'dashicons-editor-help', 'dashicons-editor-up-arrow' ]; ?> <label> <span class="customize-control-title"><?php echo esc_html($this->label); ?></span> <?php if ($this->description): ?> <span class="description customize-control-description"><?php echo esc_html($this->description); ?></span> <?php endif; ?> <div class="icon-picker-wrapper"> <?php foreach ($icons as $icon): $selected = ($this->value() === $icon) ? 'selected' : ''; ?> <span class="dashicons <?php echo esc_attr($icon); ?> <?php echo esc_attr($selected); ?>" data-icon="<?php echo esc_attr($icon); ?>"></span> <?php endforeach; ?> <input type="hidden" <?php $this->link(); ?> value="<?php echo esc_attr($this->value()); ?>"> </div> </label> <style> .icon-picker-wrapper { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; } .icon-picker-wrapper .dashicons { font-size: 24px; padding: 8px; border: 1px solid #ccc; cursor: pointer; background: #fff; border-radius: 4px; } .icon-picker-wrapper .dashicons.selected { border-color: #007cba; background-color: #e6f7ff; } </style> <script> (function($){ $(function(){ const wrapper = $('.icon-picker-wrapper'); wrapper.on('click', '.dashicons', function() { wrapper.find('.dashicons').removeClass('selected'); $(this).addClass('selected'); const icon = $(this).data('icon'); wrapper.find('input[type="hidden"]').val(icon).trigger('change'); }); }); })(jQuery); </script> <?php } } }
Save
Back