1

I have this function:

function test_add_my_stylesheet() {
    wp_register_style( 'test-admin-style', plugins_url('../css/style.css', __FILE__) );
    wp_enqueue_style( 'test-admin-style' );
}

but the css is not loaded in my admin area. Why?

In the html source code from the browser it looks like this:

<link rel='stylesheet' id='test-admin-style-css'  href='http://www.******.com/wp-content/plugins/******/includes/../css/style.css?ver=3.6.1' type='text/css' media='all' />

instead of:

<link rel='stylesheet' id='test-admin-style-css'  href='http://www.******.com/wp-content/plugins/******/css/style.css?ver=3.6.1' type='text/css' media='all' />

Why is that?

how can I fix this part:

/plugins/*******/includes/../css/style.css

to the correct one:

/plugins/*******/css/style.css
2
  • I don't see a problem here, the two URLs should fetch the same file. have you actually tried to load the "faulty" url in your browser and see what error do you get? Commented Nov 4, 2013 at 10:05
  • Hmm, seems that __FILE__ is causing the problem
    – Derfder
    Commented Nov 4, 2013 at 11:09

2 Answers 2

3

plugins_url

plugins_url( $path, $plugin );

You can use:

wp_enqueue_style( 'test-admin-style', plugins_url( 'plugin-unique-name/css/plugin.min.css') );

or you can use

wp_enqueue_style( 'test-admin-style', plugins_url( 'css/admin.min.css', __FILE__ ) );
1

I am just using

    wp_enqueue_style( 'bootstrap', get_stylesheet_directory_uri() . '/css/bootstrap.min.css');
1
  • Please add an explanation to your answer: why could that solve the problem?
    – fuxia
    Commented Nov 4, 2013 at 12:34

Your Answer

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

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