php - 覆盖 WordPress 子主题中的自定义 Logo 参数

标签 php wordpress

我正在制作一个基于 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 的原因是 10add_action() 的默认优先级>:https://developer.wordpress.org/reference/functions/add_action/#parameters

关于php - 覆盖 WordPress 子主题中的自定义 Logo 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42590242/

相关文章:

php - 使用聚合(分组)函数的 CGridView 过滤 - 例如 MAX()

php - php循环打印字符串

php - mysql_query 返回一行,但 mysql_fetch_array 不做任何事情

javascript - 将 Google 转换代码添加到 WordPress Contact Form 7

php - 在 WooCommerce 中添加到购物车后重新标记 "add to cart"按钮

wordpress - Nginx WordPress 多站点重写子目录安装规则

php - 如果变量是 int 值,array_combine php 函数不会保留字符串变量的数据类型

php - html 复选框遇到问题

javascript - WordPress : Post Content Need in the bootstrap modals without repeating the model in loop

wordpress - WooCommerce 法典 : How to create an order from an existing cart (wc_create_order)