Reputation: 1345
I was trying to include a css file in my WordPress plugin admin page. I have tried below method
function theme_name_scripts() {
wp_enqueue_style( 'jspro', '/includes/parts/css/jspro.min.css');
}
But unfortunately it doesn't work. My css file path is correct as given here,and I have tried almost every method. Any idea?
Upvotes: 0
Views: 5194
Reputation: 381
In admin mode there is a special hook 'admin_enqueue_scripts' that WP reccomends to use.
add_action('admin_enqueue_scripts', 'theme_name_scripts');
function theme_name_scripts() {
wp_enqueue_style('jspro', '/includes/parts/css/jspro.min.css');
}
Also, hook can also be used to check the name of current admin page:
function theme_name_scripts( $hook ) {
if ( $hook != 'edit.php' )
return;
wp_enqueue_style('jspro', '/includes/parts/css/jspro.min.css');
}
Upvotes: 1
Reputation: 27112
You need to have an absolute URL to your css file, and hook into the correct admin hook (in this case, 'admin_init'
):
add_action( 'admin_init', 'theme_name_scripts' );
function theme_name_scripts() {
wp_enqueue_style( 'jspro', plugins_url('includes/parts/css/jspro.min.css', __FILE__));
}
Upvotes: 4