簡體   English   中英

在Wordpress中自定義徽標的add_image_size

[英]add_image_size for custom logo in Wordpress

我使用以下代碼使用戶能夠為我的wordpress主題上傳自定義徽標:

function mytheme_setup() {
    add_theme_support('custom-logo');
}

add_action('after_setup_theme', 'mytheme_setup');

我嘗試使用add_image_sizeadd_image_size渲染徽標:

add_image_size('mytheme-logo', 180, 180);
add_theme_support('custom-logo', array(
    'size' => 'mytheme-logo'
));

要在我的主題中顯示徽標,我使用了:

<?php
    // Display the Custom Logo
    the_custom_logo('mytheme-logo');
    // No Custom Logo, just display the site's name
    if (!has_custom_logo()) {
?>
        <h1 style="text-align:center;"><?php bloginfo('name'); ?></h1>
        <?php
    }
?>

所以我現在可以上傳和顯示徽標,但似乎圖像不受add_image_size影響。 wordrpress不會調整圖像大小,這是一個問題,因為它可能會影響網站的加載時間。

我在這里做錯了嗎?

遺憾的是,Custom Logo add_theme_support()調用不再支持直接引用自定義圖像大小:

Custom Logo不再支持size參數。 在單個參數中指定徽標大小的優點是,只為所使用的特定徽標(而不是每個上載的圖像)創建特殊圖像文件,並提供更多與自定義標題工作方式相同的圖像。

(來自Make Wordpress Core上的Custom Logo

但是,它是一個簡單 - 可以說是優越 - 上面描述的修復:只需添加寬度和高度作為參數:

add_theme_support('custom-logo', array(
    'width' => 180,
    'height' => 180,
));

然后,您可以完全放棄對add_image_size()調用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM