remove_image_size() - WordPress 函数参考中文文档

返回介绍

remove_image_size()

发布于 2017-09-11 字数2323 浏览 697 评论 0

remove_image_size( string $name )

Remove a new image size.


描述


参数

$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;
}

更新日志

Version 描述
3.9.0 Introduced.

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');

上一篇:remove_filter()

下一篇:remove_menu_page()

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!