dtid30526 2015-02-11 21:06
浏览 82
已采纳

Wordpress儿童主题路径

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.

  • 写回答

1条回答 默认 最新

  • dongxian0320 2015-02-11 21:14
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 echarts动画效果失效的问题。官网下载的例子。
  • ¥60 许可证msc licensing软件报错显示已有相同版本软件,但是下一步显示无法读取日志目录。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加