0

I use this to link to my CSS file:

$css_file = plugin_dir_path( __FILE__ ) . 'MapStyle.css';
echo '<link rel="stylesheet" href="', $css_file, '" >';

Which (correctly) resolves as (echo $css_file):

/var/www/mysite/wp-content/plugins/TheMapPlugin/MapStyle.css

But the css file is never loaded, because the browser is looking for the file:

http://www.example.com/var/www/mysite/wp-content/plugins/TheMapPlugin/MapStyle.css

What am I overlooking here? All help appreciated!

1 Answer 1

0

First you need to register the style and css using wp_register_script() and wp_register_style() functions

 //registering css
 wp_register_style ( 'mysample', plugins_url ( 'css/MapStyle.css', __FILE__ ) );
 wp_register_script ( 'mysample', plugins_url ( 'js/MapStyle.js', __FILE__ ) );

After this you can call the wp_enqueue_style() functions for loading the css in required page

wp_enqueue_style('mysample');
wp_enqueue_script('mysample');
2
  • Great :-) That worked like a charm! Just a question: are there similar methods for JS and images?
    – Borniet
    Commented Jan 4, 2017 at 12:55
  • 1
    For images you can use plugins_url ( 'img/image.png', __FILE__ ) Commented Jan 4, 2017 at 13:01

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.