2015-02-08 155 views
0

我想要創建一個子主題覆蓋在我父主題的一些功能WordPress的兒童主題include_once

我有這個在父母的functions.php主題

include_once('admin/functions-extended/fn-typography.php'); //User Typography 

這是我的嘗試:

include_once(get_stylesheet_directory().'admin/functions-extended/fn-typography.php'); 

但不起作用

詳情

我試圖在這個文件中,但在兒童主題添加自定義字體 父FN-typography.php代碼

function mgm_get_google_fonts() { 
// Google Font Defaults 
$google_faces = array(
    "Abel" => "Abel", 
    "Abril Fatface" => "Abril Fatface", 
    "Aclonica" => "Aclonica", 
    "Acme" => "Acme", 
    "Actor" => "Actor", 
    "Adamina" => "Adamina", 
    "Advent Pro" => "Advent Pro", 
    "Aguafina Script" => "Aguafina Script", 
    "Aladin" => "Aladin", 
    "Aldrich" => "Aldrich", 
    "Alegreya" => "Alegreya", 
    "Alegreya SC" => "Alegreya SC", 
    "Alex Brush" => "Alex Brush", 
    "Alfa Slab One" => "Alfa Slab One", 
    "Alice" => "Alice", 
    "Alike" => "Alike", 
    "Alike Angular" => "Alike Angular", 
    "Allan" => "Allan", 
      ); 
return $google_faces; 
    } 

我想刪除該字體,並添加另一種字體

+0

你試圖使用FN-typography.php或覆蓋呢? – bobdye 2015-02-08 20:48:47

+0

@bobdye即時通訊試圖超越它 – 2015-02-08 21:23:06

+0

你有完全相同的目錄結構中的同名文件,你的孩子主題?另外,父函數.php是否允許?如果你只是再次包含一個函數,你會得到一個「重複函數名稱」錯誤。 – bobdye 2015-02-08 21:54:19

回答

0

在你展示的代碼,mgm_get_google_fonts()不實際加載的字體,但顯然提供了一些其他的功能加載字體列表。

父功能註釋把它描述爲提供默認值,因此意味着有一些方法來覆蓋它們。通過查看父函數.php,你可能會想出如何做到這一點。

例如,如果父主題,讓你超越此功能,它可能會這樣說:

if (!function_exists('mgm_get_google_fonts') { 
    ...the function definition you have above... 
} 

這個測試,看看你是否已經在你的子主題定義的名稱相同的功能並使用你的,如果你有。

如果父主題並沒有這樣做,他們將需要尋找其中mgm_get_google_fonts被調用,並追查如何重寫。

0

不管發生什麼在您的父級functions.php中也將由您的子主題完成,因此您不必單獨包含該文件,因爲它將在激活您的子主題時包含在內。

如果你想改變你的主題所包含的文件中的行爲,你不能重寫槽get_template_part(比如庫PHP文件),那麼你應該尋找主題構建器爲你實現的技術,如果有的話。大部分是通過鉤子。