Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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.

<?php
/**
 * 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;
}
share|improve this answer
    
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? –  goto10 Dec 11 '11 at 0:24

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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