Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Wordpress Child Theme Path in Wordpress

Tags:

I have a parent and child theme. In my child theme I declared a variable CHILD_DIR so I can add custom JS and CSS files to the my child theme's folder structure. I did this in my functions.php file in my child theme by doing this:

define( 'CHILD_DIR', get_stylesheet_directory_uri() ); 

This produces a URL which is what I want since I'm using it like this:

wp_enqueue_script('custom', CHILD_DIR .'/custom.js', array( 'jquery' )); 

I also added some additional folders to my child theme which I want to use within a Wordpress page. I tried to do something like this:

require_once CHILD_DIR . '/Zend/Loader.php'; 

I get an error since it's trying to provide a URL and I want a menu path to include the PHP and not try and make it an HTTP request. How can I define a path for the PHP instead of a URL to default to my child theme?

like image 877
user1048676 Avatar asked Nov 18 '13 23:11

user1048676


People also ask

How do I find the child theme folder?

In the case a child theme is being used, the absolute path to the parent theme directory will be returned. Use get_stylesheet_directory() to get the absolute path to the child theme directory. To retrieve the URI of the stylesheet directory use get_stylesheet_directory_uri() instead.

How do I find my child theme URL?

get_stylesheet_directory_uri() will return the child theme directory url, you got that bit just right. ( get_template_directory_uri() would return the parent theme directory url.) Also, if you want styles. css outputted, the first line of code will do that.

How do I find the path of a directory in WordPress?

You can use get_site_url() function to get the base url of the wordpress site. Show activity on this post. First of all, this returns the path to the current template, and second, it returns the URI, not the filesystem path.

How do I find my WordPress theme URL?

You need to find the one with /wp-content/themes in the URL. You may be able to find the Theme's URL or Theme Author's URL here which will lead you to the theme used by the website. Many WordPress sites use child themes to customize their websites.


1 Answers

It's almost the same functions:

  • Parent theme: get_template_directory()
  • Parent theme or child theme: get_stylesheet_directory()
like image 98
brasofilo Avatar answered Oct 07 '22 17:10

brasofilo