make admin.css in my child theme

i want hide elements of admin with css file my-admin.css I put css file my-admin.css at the root of my child theme wordpress and use this code in functions.php

but does not work?

there may be an error?

thank you ! :

?php
/*
activation theme
*/
function wpm_enqueue_styles(){
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
}
add_action( 'wp_enqueue_scripts', 'wpm_enqueue_styles' );

/*
admin stylesheet
*/
function wp245372_admin_enqueue_scripts() {
    wp_enqueue_style( 'my-admin-css', get_template_directory_uri() . '/my-admin.css' );
}
add_action( 'admin_enqueue_scripts', 'wp245372_admin_enqueue_scripts' );

Topic admin-css wp-enqueue-style Wordpress

Category Web


The get_template_directory_uri() function gets the URL to the parent theme. The equivalent function for child themes is get_stylesheet_directory_uri().

However these days the proper function to use to get the URL for a file in a child theme is get_theme_file_uri():

function wp245372_admin_enqueue_scripts() {
    wp_enqueue_style( 'my-admin-css', get_theme_file_uri( 'my-admin.css' ) );
}
add_action( 'admin_enqueue_scripts', 'wp245372_admin_enqueue_scripts' );

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.