簡體   English   中英

wordpress中的兒童主題網址

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM