aggiunta di un foglio di stile personalizzato a wp-admin
2 risposta
- voti
-
- 2013-08-20
Secondoil codice WordPress ( qui ):
admin_enqueue_scripts è laprima azione collegata all'amministratore azioni di script.
<"Esempio"
Caricamento di unfile CSS o JSpertutta l'area di amministrazione:
<?php //from functions.php //First solution : one file //If you're using a child theme you could use: // get_stylesheet_directory_uri() instead of get_template_directory_uri() add_action( 'admin_enqueue_scripts', 'load_admin_style' ); function load_admin_style() { wp_register_style( 'admin_css', get_template_directory_uri() . '/admin-style.css', false, '1.0.0' ); //OR wp_enqueue_style( 'admin_css', get_template_directory_uri() . '/admin-style.css', false, '1.0.0' ); } //Second solution : two or more files. //If you're using a child theme you could use: // get_stylesheet_directory_uri() instead of get_template_directory_uri() add_action( 'admin_enqueue_scripts', 'load_admin_styles' ); function load_admin_styles() { wp_enqueue_style( 'admin_css_foo', get_template_directory_uri() . '/admin-style-foo.css', false, '1.0.0' ); wp_enqueue_style( 'admin_css_bar', get_template_directory_uri() . '/admin-style-bar.css', false, '1.0.0' ); } ?>
devo creare una cartellanei mieiplugin chiamata css o devo semplicemente copiare my .cssnella directory wp-admin/css?
No,metti il tuofile CSSinsieme all'altro,nella directory deltema,quindi specificailpercorso con:
get_template_directory_uri() . '/PATH_TO_YOUR_FILE'
Adesempioilnome delmiofile è
admin-style.css
e lomettoin una cartella denominatacss
ilmiopercorso sarà simile a:get_template_directory_uri() . '/css/admin-style.css'
Spero che aiuti!
According to WordPress Codex (here):
admin_enqueue_scripts is the first action hooked into the admin scripts actions.
Example
Loading a CSS or JS files for all admin area:
<?php //from functions.php //First solution : one file //If you're using a child theme you could use: // get_stylesheet_directory_uri() instead of get_template_directory_uri() add_action( 'admin_enqueue_scripts', 'load_admin_style' ); function load_admin_style() { wp_register_style( 'admin_css', get_template_directory_uri() . '/admin-style.css', false, '1.0.0' ); //OR wp_enqueue_style( 'admin_css', get_template_directory_uri() . '/admin-style.css', false, '1.0.0' ); } //Second solution : two or more files. //If you're using a child theme you could use: // get_stylesheet_directory_uri() instead of get_template_directory_uri() add_action( 'admin_enqueue_scripts', 'load_admin_styles' ); function load_admin_styles() { wp_enqueue_style( 'admin_css_foo', get_template_directory_uri() . '/admin-style-foo.css', false, '1.0.0' ); wp_enqueue_style( 'admin_css_bar', get_template_directory_uri() . '/admin-style-bar.css', false, '1.0.0' ); } ?>
do i have to create folder in my plugins named css or do i just copy my .css to the wp-admin/css directory?
No, put your CSS file together with the other, in your theme directory, then specify the path with:
get_template_directory_uri() . '/PATH_TO_YOUR_FILE'
For ex my file name is
admin-style.css
and i put it in a folder namedcss
my path will looks like:get_template_directory_uri() . '/css/admin-style.css'
Hope it helps!
-
posso solo chiedere,se voglioimportare altri 3fogli di stile.devo solo aggiungere (x3) di questaparte `wp_register_style ('admin_css',get_template_directory_uri (). '/admin-style.css',false,'1.0.0');` o unafunzione separata?may i just ask, if i want to import 3 more stylesheets. do i just add (x3) of this part `wp_register_style( 'admin_css', get_template_directory_uri() . '/admin-style.css', false, '1.0.0' );` or a separate function?
- 0
- 2013-08-20
- user1933824
-
`wp_register_style`immediatamente seguito dal relativo` wp_enqueue_style` (comein 'Prima soluzione') è assolutamenteinutilee nonfaniente dipiù/diverso che usare semplicemente `wp_enqueue_style` contuttii parametripassati a` wp_register_style`.`wp_register_style` immediately followed by the related `wp_enqueue_style` (as in 'First solution') is absolutely unncessary and does nothing more/different than just use `wp_enqueue_style` with all params passed to `wp_register_style`.
- 1
- 2013-09-02
- gmazzap
-
Poiché sto usando un childtheme,ho cambiato lafunzionepathin `get_stylesheet_directory_uri ()`Because I'm using a child theme I changed the path function to `get_stylesheet_directory_uri()`
- 1
- 2017-06-19
- Cazuma Nii Cavalcanti
-
- 2019-02-12
Se desideri apportaremodifiche CSSperilpannello di amministrazione.incollail codice seguentein functions.php deltuo childtheme
add_action('admin_head', 'my_custom_fonts'); // admin_head is a hook my_custom_fonts is a function we are adding it to the hook function my_custom_fonts() { echo '<style> #posts-filter table.posts{ table-layout:auto; } </style>'; }
If you want to make CSS changes for the admin panel. paste the below code in functions.php of your child theme
add_action('admin_head', 'my_custom_fonts'); // admin_head is a hook my_custom_fonts is a function we are adding it to the hook function my_custom_fonts() { echo '<style> #posts-filter table.posts{ table-layout:auto; } </style>'; }
-
Grazieper quella soluzione rapida!Thanks for that quick fix!
- 1
- 2020-01-10
- NSukonny
hoproblemi afarfunzionareilmiofoglio di stilepersonalizzatonell'area WP-ADMIN.
plugins_url('style.css', __FILE__) );
devo creare una cartellanei mieiplugin chiamata css o copio semplicementeilmio.css
nelwp-admin/css
?hoprovatoentrambi,manon sembrafunzionareperme.
e quali valori devonoessere sostituitiin
__FILE__
?scusa,sono unpo 'nuovoin queste cose.