Advertisement
rAthus

[WordPress] add select2 to wp-admin panel

Jan 14th, 2021
887
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.72 KB | None | 0 0
  1. // Ajouter select2 à l'admin
  2. function enqueue_select2_jquery() {
  3.     wp_register_style('select2css', '//cdnjs.cloudflare.com/ajax/libs/select2/3.4.8/select2.css', false, '1.0', 'all');
  4.     wp_register_script('select2', '//cdnjs.cloudflare.com/ajax/libs/select2/3.4.8/select2.js', array('jquery'), '1.0', true);
  5.     wp_enqueue_style('select2css');
  6.     wp_enqueue_script('select2');
  7. }
  8. add_action('admin_enqueue_scripts', 'enqueue_select2_jquery');
  9. function custom_admin_js_css() {
  10.     echo '<script>
  11.             jQuery(document).ready(function($) {
  12.                 $(\'[name="post_author_override"]\').select2();
  13.             });
  14.         </script>
  15.         <style>
  16.             .select2-container {
  17.                 width:100%;
  18.             }
  19.         </style>';
  20. }
  21. add_action('admin_footer', 'custom_admin_js_css');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement