在Wordpress中自定义徽标的add_image_size

时间:2016-05-31 00:57:15

标签: php wordpress

我使用以下代码让用户为我的wordpress主题上传自定义徽标:

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

add_action('after_setup_theme', 'mytheme_setup');

我已尝试实施add_image_size以180x180px呈现徽标:

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不会调整图像大小,这是一个问题,因为它可能会影响网站的加载时间。

我在这里做错了吗?

1 个答案:

答案 0 :(得分:0)

很遗憾,自定义徽标js: { main: 'app/main.js', src: [ // application config 'app.config.js', // application bootstrap file 'app/main.js', // main module 'app/app.js', // module files 'app/**/module.js', // other js files [controllers, services, etc.] 'app/**/!(module)*.js' ], tpl: 'app/**/*.html' } 来电不再支持直接引用自定义图片尺寸:

  

Custom Logo不再支持size参数。在单个参数中指定徽标大小的优点是只为所使用的特定徽标(而不是每个上传的图像)创建特殊图像文件,并提供更多与自定义标题工作方式相同的图像。

(来自Custom Logo on Make Wordpress Core

然而,它是一个简单且可以说是优越的修复:只需添加宽度和高度作为参数:

add_theme_support()

然后,您可以完全停止拨打add_theme_support('custom-logo', array( 'width' => 180, 'height' => 180, ));