wordpress中的儿童主题网址

时间:2013-09-10 16:12:53

标签: wordpress

我想在wordpress中创建一个网站,为此我采取主题并创建一个儿童主题。

我在子文件夹中复制了一个style.css和header.php,因为我也想修改标题。我修改了孩子的文件。

在我的style.css中,我添加了模板行:父主题的名称

/*
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...

任何想法

2 个答案:

答案 0 :(得分:29)

您需要get_stylesheet_directory_uri,此功能首先在子主题目录中检查,然后在父主目录中检查。您正在使用的那个只检查父目录。

底线:如果某个功能的行为与预期不符,请检查Codex。很可能你会在那里找到原因。

答案 1 :(得分:-1)

添加到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;
}