我正在制作一个基于 Shapely 的 child 主题.在 Shapely 的 functions.php
中,声明了自定义 Logo 支持。
/**
* Add support for the custom logo functionality
*/
add_theme_support( 'custom-logo', array(
'height' => 55,
'width' => 136,
'flex-width' => true,
) );
在我的子主题的 functions.php
中,我试着写:
function override_shapely_customlogo() {
add_theme_support( 'custom-logo', array(
'width' => 168,
'flex-height' => true,
) );
}
add_action( 'after_setup_theme', 'override_shapely_customlogo' );
但这似乎没有做任何事情。
有没有办法让子主题覆盖自定义 Logo 支持参数?
最佳答案
进行了一些挖掘,我确实遇到了一些错误的线索,但我做到了。事实证明,您完全可以覆盖 theme_support
函数。但是,您的代码与 Shapely 的代码具有完全相同的优先级和操作 Hook ,因此最后执行的代码获胜。
并且(这里是需要一些研究的部分)子主题的 functions.php
实际上在父主题的 之前执行:
[T]he functions.php of a child theme does not override its counterpart from the parent. Instead, it is loaded in addition to the parent’s functions.php. (Specifically, it is loaded right before the parent’s file.)
From the Codex ,强调我的。因此,我们要做的就是为您的代码赋予更高的执行优先级。
<?php
function override_shapely_customlogo() {
add_theme_support( 'custom-logo', array(
'width' => 168,
'flex-height' => true,
) );
}
add_action( 'after_setup_theme', 'override_shapely_customlogo', 11 );
?>
编辑:只是想补充一点,我在这里选择优先级 11
的原因是 10
是 add_action()
的默认优先级>:https://developer.wordpress.org/reference/functions/add_action/#parameters
关于php - 覆盖 WordPress 子主题中的自定义 Logo 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42590242/