Get Current Plugin URL
Join the DZone community and get the full member experience.Join For Free
wp_enqueue_style('stylsheet', 'http://www.example.com/stylesheet.css' );
wp_enqueue_style('stylsheet', 'http://www.example.com/wp-content/plugins/example-plugin/css/stylesheet.css' );
This will work fine but it's not best practice, for example you can only use this on the one domain, you can't move this plugin inside the mu-plugins folder and you can't change the name of the plugin folder.
So to get around these problems WordPress comes with a very useful function called plugins_url(), you give this function the filepath and it will return with the URL to this plugin. It is very useful to use when you need to include Savascript or CSS files in your plugin.
$url = plugins_url( $path, $plugin );
If you want to include a stylesheet from within a plugin the best way to do this is to use the global variable __FILE__ as the second parameter, this will always return the URL root of the plugin.
So if your stylesheet is in a css folder on the root of your plugin you will enqueue it by using the following code.
wp_enqueue_style('stylsheet', plugins_url( 'css/stylesheet.css', __FILE__ ) );
Published at DZone with permission of Paul Underwood, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Building the World's Most Resilient To-Do List Application With Node.js, K8s, and Distributed SQL
Understanding Data Compaction in 3 Minutes
AI and Cybersecurity Protecting Against Emerging Threats
Rule-Based Prompts: How To Streamline Error Handling and Boost Team Efficiency With ChatGPT