问题描述:

I want to create a website in wordpress, for this I take a theme and create a child theme.

I copy in the folder of the child a style.css and header.php, because I want to modify the header too. I modify the file of the child.

In my style.css I add the line Template: with the name of the father theme

/*

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

*/

I am using this line in the header.php

<?php $logo = esc_url( get_template_directory_uri() . 'images/logo.png' ); ?>

of my child theme to take a images but this line return the url of the father theme no his child!

I take this.

http://localhost/.../wp-content/themes/mystile/images/...

I I want this

http://localhost/.../wp-content/themes/example/images...

any idea

网友答案:

You need get_stylesheet_directory_uri, this function checks first in the child theme directory and then in the parent's. The one you're using only checks in the parent directory.

Bottom line: if a function doesn't behave as you expect, check the Codex. Much probably you'll find out why over there.

网友答案:

Add to 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;
}
相关阅读:
Top