[英]url of child theme in wordpress
我想在wordpress中创建一个网站,为此我采取主题并创建一个儿童主题。
我在子文件夹中复制了一个style.css和header.php,因为我也想修改标题。 我修改了孩子的文件。
在我的style.css中,我添加了Template:行,其中包含父主题的名称
/*
Theme Name: Example
Theme URI: http://www.woothemes.com/
Version: 1.2.15
Description: Designed by <a href="http://www.woothemes.com">WooThemes</a>.
Author: WooThemes
Author URI: http://www.woothemes.com
Tags: woothemes
Template: mystile
Copyright: (c) 2009-2011 WooThemes.
License: GNU General Public License v2.0
License URI: http://www.gnu.org/licenses/gpl-2.0.html
*/
我在header.php中使用这一行
<?php $logo = esc_url( get_template_directory_uri() . 'images/logo.png' ); ?>
我的孩子主题采取图像,但这行返回父亲主题的网址没有他的孩子!
我接受了。
http://localhost/.../wp-content/themes/mystile/images/...
我想要这个
http://localhost/.../wp-content/themes/example/images...
任何想法
你需要get_stylesheet_directory_uri
,这个函数先检查子主题目录,然后检查父目录。 您正在使用的那个只检查父目录。
底线:如果某个功能的行为不符合您的预期,请检查Codex。 很可能你会发现为什么那边。
添加到functions.php
:
// create a URL to the child theme
function get_template_directory_child() {
$directory_template = get_template_directory_uri();
$directory_child = str_replace('storefront', '', $directory_template) . 'child-storefront';
return $directory_child;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.