mytechead

Android & Wordpress Help center

get wordpress themes directory path

While coding for my wordpress blog i came across a scenario where i had to use the directory path of my WP themes folder. It was basically required to use the php method ‘include()’ which requires directory path of the file to be included.

To obtain the directorypath you can do something like this :

$template_url = get_bloginfo("template_url");
$theme_name = explode("wp-content/themes/",$template_url);
$theme_file_path = get_theme_root() ."/". $theme_name[1];

Here the first line obtains the ‘href’ for the template or themes directory of the WP installation.

In the next line we explode the url at ”wp-content/themes/”, so the path of SELECTED /ACTIVATED theme on your blog comes in the 1st location of the array $theme_name ( $theme_name[1] ) .

get_theme_root() methods gives us the directory path till ‘wp-content/themes’ folder [without the trailing slash]

In the 3rd line we concatenate get_theme_root() with the activated theme path to obtain a full path to our themes directory [activated themes directory to be precise]

Hope it helps!!

Advertisements

Single Post Navigation

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: