I am trying to get the path to the themes CSS file from inside a Plugin, anyone know how to do this?


Get the absolute path: get_stylesheet_directory()

Get the URI: get_stylesheet_directory_uri()

Edit: Here's a proof of concept plugin. It will just print out the stylesheet path and uri in the head tag of your site (front end). If these functions are not working in your plugin, there might be some other factor not explained in the OP. Please post your code.

 * Plugin Name: Get Style Sheet Test
 * Plugin URI: 
 * Description: Demonstration of get_stylesheet_directory() and get_stylesheet_directory_uri() within a plugin.
 * Version: 1.0
 * Author: goto10
 * Author URI: 
 * License: 

add_action( 'wp_head', 'get_stylesheet_dir_and_uri_test' );

function get_stylesheet_dir_and_uri_test() {
    $output = "<!-- \nGet the absolute path using get_stylesheet_directory(): " . get_stylesheet_directory() . "\n";
    $output .= "Get the URI using get_stylesheet_directory_uri(): " . get_stylesheet_directory_uri() . "\n -->";
    echo $output;
  • Hello that is what I thought would work however when used in a plugin file I get Fatal error: Call to undefined function get_stylesheet_directory() so the plugin file doesn't have access to the file containing that function, any ideas for a fix
    – JasonDavis
    Dec 10 '11 at 10:37
  • Hrmm, not sure. Added example plugin. Can you post your code? Dec 11 '11 at 0:24

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.