Php WordPress子主题包括一次

Php WordPress子主题包括一次,php,wordpress,Php,Wordpress,我试图创建一个子主题来覆盖父主题中的一些函数 我在parentfunctions.php主题中有这个 include_once('admin/functions-extended/fn-typography.php'); //User Typography 这是我的尝试: include_once(get_stylesheet_directory().'admin/functions-extended/fn-typography.php' ); 但不起作用 更多细节 我正在尝试在此文件

我试图创建一个子主题来覆盖父主题中的一些函数

我在parentfunctions.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;
   }

我希望删除此字体并添加另一个字体

无论在父函数中发生什么。php也将由子主题完成,因此您不必单独包含该文件,因为它将在激活子主题时包含


如果您想更改主题包含的文件中的行为,而该文件不能通过像库PHP文件那样的get_template_部分来覆盖,那么您应该寻找主题生成器为您实现的技术(如果有的话)。大多数情况下是通过钩子实现的。

在您展示的代码中,mgm\u get\u google\u字体实际上并没有加载字体,但显然提供了一个字体列表,供其他一些功能加载

父函数中的注释将其描述为提供默认值,因此暗示有某种方法可以覆盖它们。通过查看parentfunctions.php,您可能会发现如何做到这一点

例如,如果父主题允许您重写此函数,它可能会说:

if ( !function_exists( 'mgm_get_google_fonts') {
    ...the function definition you have above...
}
这将测试您是否在子主题中定义了相同名称的函数,如果有,将使用您的函数


如果父主题不这样做,您需要查看调用mgm_get_google_fonts的位置,并跟踪如何覆盖。

您是在尝试使用fn-typography.php还是覆盖它?@bobdye我在尝试覆盖它您的子主题中是否有完全相同的目录结构中的同名文件?另外,父函数function.php允许吗?如果您只是再次包含一个函数,您将得到一个重复的函数名错误。@bobdye那么如何在函数mgm\u get\u google\u font中的子主题中添加一些自定义字体{