Hinzufügen eines benutzerdefinierten Stylesheets zu wp-admin
2 Antworten
- Stimmen
-
- 2013-08-20
Laut WordPress Codex ( hier ):
admin_enqueue_scripts ist dieerste Aktion,diemit dem Administrator verknüpftist Skriptaktionen.
Beispiel
Ladeneiner CSS- oder JS-Dateifür dengesamten Administratorbereich:
<?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' ); } ?>
Mussichin meinen Pluginseinen Ordnermit dem Namen csserstellen odermussichnur kopieren? meine .cssin das Verzeichnis wp-admin/css?
Nein,fügen Sie Ihre CSS-Datei zusammenmit der anderenin Ihrem Themenverzeichnisein undgeben Sie den Pfadmit:
anget_template_directory_uri() . '/PATH_TO_YOUR_FILE'
Zum Beispiel lautetmein Dateiname
admin-style.css
undich legeihnin einen Ordnermit dem Namencss
. Mein Pfad siehtfolgendermaßen aus:get_template_directory_uri() . '/css/admin-style.css'
Hoffees hilft!
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!
-
Darfichnurfragen,obich 3 weitere Stylesheetsimportierenmöchte.fügeicheinfach (x3) dieses Teils `wp_register_style ('admin_css',get_template_directory_uri (). '/admin-style.css',false,'1.0.0') hinzu;` odereine separate Funktion?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" unmittelbargefolgt von dem zugehörigen "wp_enqueue_style" (wiein "Erste Lösung")ist absolut unnötig undmachtnichts anderes als die Verwendung von "wp_enqueue_style"mit allen an "wp_register_style" übergebenen Parametern.`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
-
Daichein untergeordnetes Thema verwende,habeich die Pfadfunktionin "get_stylesheet_directory_uri ()"geändertBecause 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
Wenn Sie CSS-Änderungenfür das Admin-Panel vornehmenmöchten.Fügen Sie denfolgenden Codein die Dateifunctions.php Ihres untergeordneten Themas
einadd_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>'; }
-
Vielen Dankfür die schnelle Lösung!Thanks for that quick fix!
- 1
- 2020-01-10
- NSukonny
Ich habe Probleme damit,dassmein benutzerdefiniertes Stylesheetim WP-ADMIN-Bereichfunktioniert.
plugins_url('style.css', __FILE__) );
mussichin meinen Pluginseinen Ordnermit dem Namen csserstellen oder kopiereicheinfachmeinen.css
in denwp-admin/css
?Ich habebeide ausprobiert,es scheintnichtfürmich zufunktionieren.
und welche Werte sollten durch
__FILE__
ersetzt werden?Entschuldigung,ichbin einbisschenneuin diesen Sachen.