WordPress儿童主题包含一次


WordPress Child Themes include_once

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

我在父函数中有这个。php主题

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

这是我的尝试:

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

但不能工作

更多详细信息

我正在尝试在此文件中添加自定义字体,但在子主题中parent fn-typograpy.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;
   }

我想删除这些字体并添加另一种字体

在您显示的代码中,mgm_get_google_fonts()实际上并没有加载字体,但显然提供了一个字体列表供其他函数加载。

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

例如,如果父主题允许你覆盖这个函数,它可能会说:

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

这将测试您是否已在子主题中定义了同名函数,如果已定义,则使用您的函数。

如果父主题不执行此操作,则需要查看调用mgm_get_google_fonts的位置,并跟踪如何覆盖。

父函数.php中发生的任何事情也将由子主题完成,因此您不必单独包含该文件,因为它将在激活子主题时包含。

如果你想改变你的主题所包含的文件中的行为,而你不能通过get_template_part(比如库PHP文件)覆盖它,那么你应该寻找主题生成器为你实现的技术(如果有的话)。大部分是用钩子钩住的。