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!

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');
  • Great :-) That worked like a charm! Just a question: are there similar methods for JS and images? – Borniet Jan 4 '17 at 12:55
  • 1
    For images you can use plugins_url ( 'img/image.png', __FILE__ ) – Devendra Sharma Jan 4 '17 at 13:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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