简体   繁体   中英

Wordpress Child Theme Path

I'm working on my first child theme and I'm running into a lot of confusion with directories and child themes.

I won't use my real website but I have made a directory in my cPanel dedicated to working on my theme which is at www.wp.example.com

Lets call the template testTemplate. I made a child template called testTemplate-child following the Wordpress codex meaning I registered the parent theme in the child theme's function.php

So wp.example.com loads the style from both the parent theme and the child theme which is desired. What it does not load is the javascript files I enqueued in my child theme's functions.php file.

The confusing part is this, if I navigate to www.wp.example.com/testTemplate-child/ my javascript loads up and works.

I'm wondering if anyone can clear this up for me, why does my child's function.php only work in wp.example.com/testTemplate-child.

It's because your child's theme function.php is added before parent's function.php, that's why you can't override some options, also keep in mind that you'll need to call get_stylesheet_directory() to get child's theme path, because if you do another function, it will load parent's path.

Example to load a javascript file located a /js folder:

$jsPath = get_stylesheet_directory() . '/js/yourScript.js';
wp_enqueue_script( 'child-js', $jsPath, array(), '1.0', true ) 

More info at: https://codex.wordpress.org/Child_Themes

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM