简体   繁体   English

wordpress中的儿童主题网址

[英]url of child theme in wordpress

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. 我在子文件夹中复制了一个style.css和header.php,因为我也想修改标题。 I modify the file of the child. 我修改了孩子的文件。

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

II 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. 你需要get_stylesheet_directory_uri ,这个函数先检查子主题目录,然后检查父目录。 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. 底线:如果某个功能的行为不符合您的预期,请检查Codex。 Much probably you'll find out why over there. 很可能你会发现为什么那边。

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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM