wordpress wordpress中子主题的网址
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18724007/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
url of child theme in wordpress
提问by user852610
I want to create a website in wordpress, for this I take a theme and create a child theme.
我想在 wordpress 中创建一个网站,为此我选择一个主题并创建一个子主题。
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.
我在孩子的文件夹中复制了一个style.css和header.php,因为我也想修改标题。我修改了孩子的文件。
In my style.css I add the line Template: with the name of the father theme
在我的 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
*/
I am using this line in the header.php
我在 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
任何的想法
回答by brasofilo
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.
您需要get_stylesheet_directory_uri
,此函数首先检查子主题目录,然后检查父主题目录。您正在使用的那个只检查父目录。
Bottom line: if a function doesn't behave as you expect, check the Codex. Much probably you'll find out why over there.
底线:如果某个函数的行为不符合您的预期,请查看 Codex。很可能你会在那里找到原因。
回答by Carlos Ramos Web
Add to functions.php
:
添加到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;
}