0

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' );
1
  • Hello and welcome to wpse! First make sure that the file was loaded, check your devtools under network tab, select css and refresh page, if you see your file and it have status 200 it means its loaded and the problem is probably css targets or css specificity Oct 12, 2021 at 11:49

1 Answer 1

2

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' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.