37

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?

5 Answers 5

73

It's almost the same functions:

2
  • 1
    what about the JS folder ?? Mar 30, 2017 at 16:13
  • 2
    I'm not seeing how the naming are justified. Jul 23, 2017 at 5:18
18

For Retrieve Theme stylesheet directory URL:

get_theme_file_uri() oR 
get_stylesheet_directory_uri()

For Retrieve Absolute File Paths:

get_stylesheet_directory() oR 
get_theme_file_uri()
3

Main theme path : get_template_directory_uri();

Child Theme path : get_stylesheet_directory_uri(); or get_stylesheet_uri();

NOTE : Irrespective of calling js files or css files, For gettig the path of the theme or the path of the child theme we have to use the above functions.

1
define( 'CHILD_DIR',TEMPLATEPATH.'-child');

me funciono, is working

0

Hello please change the url

old:

background-image:url('<?php echo get_stylesheet_directory_uri() . "/images/bean.gif"; ?>') !important;

new:

background-image:url('<?php echo get_template_directory_uri() . "/images/bean.gif"; ?>') !important;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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