返回介绍

remove_image_size()

发布于 2017-09-11 10:08:23 字数 2325 浏览 820 评论 0 收藏 0

remove_image_size( string $name )

Remove a new image size.


description


参数

$name

(string) (Required) The image size to remove.


返回值

(bool) True if the image size was successfully removed, false on failure.


源代码

File: wp-includes/media.php

function remove_image_size( $name ) {
	global $_wp_additional_image_sizes;

	if ( isset( $_wp_additional_image_sizes[ $name ] ) ) {
		unset( $_wp_additional_image_sizes[ $name ] );
		return true;
	}

	return false;
}

更新日志

Versiondescription
3.9.0Introduced.

User Contributed Notes

  1. Skip to note content You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note Contributed by Codex

    Example

    In a theme’s functions.php file:

    
    function wpdocs_remove_plugin_image_sizes() {
    	remove_image_size( 'image-name' );
    }
    add_action('init', 'wpdocs_remove_plugin_image_sizes');
    

    You could combine this with the add_image_size function in your theme.

    
    function wpdocs_remove_then_add_image_sizes() {
    	remove_image_size( 'image-name' );
    	add_image_size( 'image-name', 200, 200, true );
    }
    add_action('init', 'wpdocs_remove_then_add_image_sizes');
    
  2. To remove all the image sizes keeping only the default WordPress image sizes –

    function remove_extra_image_sizes() {
        foreach ( get_intermediate_image_sizes() as $size ) {
            if ( !in_array( $size, array( 'thumbnail', 'medium', 'medium_large', 'large' ) ) ) {
                remove_image_size( $size );
            }
        }
    }
    
    add_action('init', 'remove_extra_image_sizes');

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文