remove image sizes from media uploader box - wordpress

I have used custom image sizes in wordpress with "add_image_size" and it's working fine.
I tried to remove default image sized with following code:
function filter_image_sizes( $sizes) {
unset( $sizes['thumbnail']);
unset( $sizes['medium']);
unset( $sizes['large']);
return $sizes;
}
add_filter('intermediate_image_sizes_advanced', 'filter_image_sizes');
But these default images sizes are still visible in media upload popup.

You may give it a try
function my_custom_image_sizes($sizes) {
unset( $sizes['thumbnail']);
unset( $sizes['medium']);
unset( $sizes['large']);
unset( $sizes['full'] ); // removes full size if needed
// add your image sizes, i.e.
$myCustomImgsizes = array(
"magazine-thumb" => __( "Magazine" ),
"slideshow-thumb" => __( "Slideshow" ),
"sidebar-thumb" => __( "Sidebar" )
);
$newimgsizes = array_merge($sizes, $myCustomImgsizes);
return $newimgsizes;
}
add_filter('image_size_names_choose', 'my_custom_image_sizes');

Tested on 3.5.1 in my localhost
Using unset and intermediate_image_sizes_advanced will work but only on images uploaded after the function is added. To change it for existing images you need to regenerate them using a plugin ( in essence deleting that image size) or just hide that option from being visible.
// add custom image size
function mytheme_95344() {
add_image_size('x-la',800,800, false);
}
add_action( 'after_setup_theme', 'mytheme_95344' );
// remove it
function remove_image_size_95344($sizes) {
unset($sizes['x-la']);
return $sizes;
}
add_filter('intermediate_image_sizes_advanced', 'remove_image_size_95344');
So this x-la size will still show for images before the unset function was added.
To remove this you can try.
Hide it from the display using image_size_names_choose
function remove_image_size_95344($possible_sizes) {
unset( $possible_sizes['x-la'] );
return $possible_sizes;
}
add_filter('image_size_names_choose', 'remove_image_size_95344');
Answer from https://wordpress.stackexchange.com/questions/95344/hide-custom-image-sizes-from-media-library#answer-95350

I tried intermediate_image_sizes_advanced and it wasn't working, so I inspected the get_intermediate_image_sizes() function and saw that they now use the intermediate_image_sizes filter hook.
So I was able to remove all image sizes by doing this.
add_filter('intermediate_image_sizes', function($size){
return [];
},9999);
Fill free to create the callback function separately so it can be unhooked.

Related

I want to stop wordpress for generating thumnails

My WordPress website is generating thumbnails for my images I want to prevent WordPress from doing that how can I achieve the same?
You can follow these steps for the same :
Step 1: In Admin Panel Go to Settings -> Media.
Step 2: Now Uncheck (Crop thumbnail) If it's Checked.
Step 3: Set at Thumbnail size, Medium size, and Large size the Width and Height to
You may use the remove_image_size() method like so:
add_action( 'init', 'so_73173777_remove_image_sizes' );
function so_73173777_remove_image_sizes() {
remove_image_size( '1200' );
remove_image_size( 'portfolio-full' );
remove_image_size( 'blog-medium' );
/* etc ... */
}
For removing default WP sizes:
add_filter( 'intermediate_image_sizes_advanced', 'so_73173777_remove_core_sizes' );
// This will remove the default image sizes and the medium_large size.
function so_73173777_remove_core_sizes( $sizes ) {
unset( $sizes['small']);
unset( $sizes['medium']);
unset( $sizes['large']);
unset( $sizes['medium_large']);
return $sizes;
}
Consider searching for these particular problems, because this took me 5 seconds to find this plugin: https://wordpress.org/plugins/disable-generate-thumbnails/

Remove Wordpress Native Audio Player Skin [duplicate]

I frequently use the Wordpress audio shortcode to embed my podcast episodes in my posts:
[audio src="http://podcastsourcefile"]
Unfortunately, the default audio player looks terrible. I would like to have it restyled with CSS. I have a mockup I can send to show you what it should look like, but here's the basic gist:
background color: #B27D47
replace play button image (I can provide the .png file)
make the player 75 pixels tall, 100% width
round the corners of the player
Here's what I would like the player to look like:
(I have the .png file of the play button.)
Consider this:
// Deactivate default MediaElement.js styles by WordPress
function remove_mediaelement_styles() {
if( is_home() ) {
wp_dequeue_style('wp-mediaelement');
wp_deregister_style('wp-mediaelement');
}
}
add_action( 'wp_print_styles', 'remove_mediaelement_styles' );
// Add own custom CSS file to reskin the audio player
function add_audio_player_styles () {
if( is_home() ) {
wp_enqueue_style('mini-audio-player', get_stylesheet_directory_uri() . '/assets/mediaelement/mediaelementplayer.css', array(), null );
}
}
add_action( 'wp_enqueue_scripts', 'add_audio_player_styles');
This way, you can now copy the whole mediaelement folder out of wp-include, enqueue your copy instead of the original and then fiddle with the .css there. The lines marked with //optional show how you can use different styles depending on the page your visitor is in. Found it here
There are two filter hooks to deal with this. One at the beginning, with very few info, with it we shortcut the whole shortcode and return our own custom HTML code:
add_filter( 'wp_audio_shortcode_override', 'short1_so_23875654', 10, 4 );
function short1_so_23875654( $return = '', $attr, $content, $instances )
{
# If $return is not an empty array, the shorcode function will stop here printing OUR HTML
// $return = '<html code here>';
return $return;
};
The parameters that arrive are:
Array
(
[0] => ''
[1] => Array
(
[src] => http://example.com/wp-content/uploads/file.mp3
)
[2] => ''
[3] => 1
)
And the other one that runs at the end of the shortcode function:
add_filter( 'wp_audio_shortcode', 'short2_so_23875654', 10, 5 );
function short2_so_23875654( $html, $atts, $audio, $post_id, $library )
{
return $html;
}
The parameters that arrive are:
Array
(
[0] => <audio class="wp-audio-shortcode" id="audio-715-1" preload="none" style="width: 100%" controls="controls"><source type="audio/mpeg" src="http://example.com/wp-content/uploads/file.mp3?_=1" />http://plugins.dev/wp-content/uploads/2013/10/04_discipline_64kb.mp3</audio>
[1] => Array
(
[class] => wp-audio-shortcode
[id] => audio-715-1
[preload] => none
[style] => width: 100%
)
[2] =>
[3] => 715
[4] => mediaelement
)
I just did it by styling my custom.css in the theme editor.
The values of the audio shortcode are the following. In my case, I changed it so it won't be affected by any Wordpress update (even if it's dirtier than the PHP solution on the other comment). You could use the developper tools and style the player your own way (my problem was that i didn't need a 100% width player).
:
.mejs-mute,
.mejs-duration-container,
.mejs-time,
.mejs-duration-container,
... {...}
I added my stylesheet additionally to the existing one, like I explained in this post:
function enqueue_mediaelement(){
wp_enqueue_style( 'wp-mediaelement' );
//enqueue '/wp-content/my-theme/audio-player-styles.css'
wp_enqueue_style('my-audio-player', get_stylesheet_directory_uri() . '/audio-player-styles.css', array(), null );
}
add_action( 'wp_enqueue_scripts', 'my_enqueue_scripts' );
For example if you want to color the players background, you could add now the following to audio-player-styles.css:
.mejs-container, .mejs-container .mejs-controls, .mejs-embed, .mejs-embed body {
background-color: #B27D47;
}

Image media is creating a new image size of 768px but how do I stop it?

After updating to WordPress 4.5 I was doing a media upload test and I noticed that I was generating a new image size that I cannot figure out how to stop.
The current function I am using to prevent generating multiple sizes of my media is:
function add_image_insert_override( $sizes ) {
unset( $sizes[ 'thumbnail' ]);
unset( $sizes[ 'medium' ]);
unset( $sizes[ 'large' ]);
unset( $sizes[ 'full' ] );
return $sizes;
}
add_filter( 'intermediate_image_sizes_advanced', 'add_image_insert_override' );
How can I stop WordPress 4.5 from generating images with a width of 768px?
I didn't find this anywhere other than the article I referenced under Responsive Images in WordPress 4.4 when they indicated that a new image size had been created:
A new default intermediate size, medium_large, has been added to
better take advantage of responsive image support. The new size is
768px wide by default, with no height limit, and can be used like any
other size available in WordPress. As it is a standard size, it will
only be generated when new images are uploaded or sizes are
regenerated with third party plugins.
After reading this article I was then able to update my function to:
function add_image_insert_override( $sizes ){
unset( $sizes[ 'thumbnail' ]);
unset( $sizes[ 'medium' ]);
unset( $sizes[ 'medium_large' ] );
unset( $sizes[ 'large' ]);
unset( $sizes[ 'full' ] );
return $sizes;
}
add_filter( 'intermediate_image_sizes_advanced', 'add_image_insert_override' );
Now when I add media to a post I am no longer generating foobar-768xwhatever. Hope this helps the next person.

Wordpress creates weird image sizes... :P

I just noticed Wordpress creates 48x48, 96x96 and 128x128 version images, when I upload something.
But, I swear, there's nothing on my functions.php about this. Any clues of how to fix this? I don't want those images, they use a lot of space... :/
Ok, the problem was the CO-AUTHORS PLUS plugin.
I just removed the image sizes with the functions.php and it's ok. :)
Try adding this to your functions.php file
function wp_filter_image_sizes( $sizes) {
unset( $sizes['medium']); unset( $sizes['large']); unset(
$sizes['wp-newsletters-max']);
return $sizes; } add_filter('intermediate_image_sizes_advanced',
'wp_filter_image_sizes');
function wp_custom_image_sizes($sizes) { $myimgsizes = array(
"image-in-post" => __( "Image in Post" ), "full" => __( "Original
size" ) ); return $myimgsizes; } add_filter('image_size_names_choose',
'wp_custom_image_sizes');

Define a new cropping image size in Wordpress

Inside Wordpress, I need to generate and create inside the upload folder a new cropping image size that has:
width=205px
height=120px
Inside my function.php here is my code:
// Call function on after setup
add_action( 'after_setup_theme', 'theme_setup_img' );
function theme_setup_img() {
add_theme_support( 'post-thumbnails' );
add_image_size('search-thumb', 205, 120, true );
// set_post_thumbnail_size( 205, 120, true );
}
However, no new image-sizes have been created inside the upload folder (only default WP sizes). Any solution?
Note: I'm using the default theme and the latest WP version
Your code looks correct. Mine is slightly different and I know it works:
if (function_exists('add_theme_support'))
{
// Add Thumbnail Theme Support
add_theme_support('post-thumbnails');
add_image_size('large', 700, '', true); // Large Thumbnail
add_image_size('medium', 250, '', true); // Medium Thumbnail
}
This was taken from the HTML5 Blank Theme by Todd Motto. Gerald also mentioned writing a script to re-render but there's a great plugin for that called Regenerate Thumbnails that does the same thing.
This might be due to you calling the new size inside the "after_setup_theme" action... I use the following code:
// Add custom image sizes
if( function_exists( 'add_image_size' ) ) {
add_image_size( 'search-thumb', 205, 120, true );
}
And it works every time... if it's inside the functions.php file, you don't need an action or hook to make it work.
Also, you can add this to functions.php to make your custom sizes show up in the drop down menus when inserting images into pages/posts/where ever:
// Functions to add custom image sizes to the media library thickbox area
// and put them into drop down
function my_insert_custom_image_sizes( $sizes ) {
// get the custom image sizes
global $_wp_additional_image_sizes;
// if there are none, just return the built-in sizes
if ( empty( $_wp_additional_image_sizes ) )
return $sizes;
// add all the custom sizes to the built-in sizes
foreach ( $_wp_additional_image_sizes as $id => $data ) {
// take the size ID (e.g., 'my-name'), replace hyphens with spaces,
// and capitalise the first letter of each word
if ( !isset($sizes[$id]) )
$sizes[$id] = ucfirst( str_replace( '-', ' ', $id ) );
}
return $sizes;
}
add_filter( 'image_size_names_choose', 'my_insert_custom_image_sizes' );
You will need a plugin (I use AJAX Thumbnail Rebuild) to resize old images already uploaded before this code was implemented.
The problem here was the "Dynamic Image Resizer" plug-in.
It was breaking my theme with Wordpress 4.0.

Resources