Wordpress creates weird image sizes... :P - wordpress

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

Related

How Can I Change the Elementor Popup Location Settings?

I have an issue with one of the websites I work on where the "edit_in_content" location setting for Elementor popups is set to FALSE for all popups, and it is preventing the admin from going to the Elementor editor.
This issue presents itself as the common "the_content not found" error message, however, debugging leads to the location settings for popups being the issue. The problem is in the builder_wrapper method of \ElementorPro\Modules\ThemeBuilder\Classes\Locations_Manager, which is in /elementor-pro/modules/theme-builder/classes/locations-manager.php.
public function builder_wrapper( $content ) {
$post_id = get_the_ID();
if ( $post_id ) {
$document = Module::instance()->get_document( $post_id );
if ( $document ) {
$document_location = $document->get_location();
$location_settings = $this->get_location( $document_location );
/**
* Custom Modification Begin
* ------------------------------------
*/
if( $document_location == 'popup' )
return $content;
/**
* Custom Modification End
* ------------------------------------
*/
// If is a `content` document or the theme is not support the document location (header/footer and etc.).
if ( $location_settings && ! $location_settings['edit_in_content'] ) {
$content = '<div class="elementor-theme-builder-content-area">' . __( 'Content Area', 'elementor-pro' ) . '</div>';
}
}
}
return $content;
}
I'm aware that this is a plugin hack, and not recommended, but I have found no other way to handle the issue.
I'm not sure why edit_in_content is FALSE for all popups.
I've found no way to ensure that edit_in_content is TRUE so that the admin can work with popups.
To be fair, I should disclose that the theme is custom, but rather minimal. When switching to twentytwenty the issue goes away. ALL plugins have been disabled during testing, and it seems that the popup location setting is somehow being affected by the custom theme.
I've found nothing in twentytwenty that references elementor in any way.
I've been through Elementor's docs related to the_content issues, and nothing noted there leads to success. Ref: https://docs.elementor.com/article/56-content-area-not-found
So, I'm hoping somebody will be able to shed some light on this issue. What can I do so I don't have to hack the plugin?
I'm posting an answer because I found something that I could do to not hack the plugin, although I'm still curious to why it needs to be done. I basically just add a hook/action that reprocesses the popup location after it was initially registered. This could go in the theme's functions.php file:
function fixElementorPopupLocation( $that )
{
$loc = $that->get_location('popup');
if( ! $loc['edit_in_content'] )
{
$args = [
'label' => $loc['label'],
'multiple' => $loc['multiple'],
'public' => $loc['public'],
'edit_in_content' => TRUE,
'hook' => $loc['hook'],
];
$that->register_location('popup', $args);
}
}
add_action(
'elementor/theme/register_locations',
'fixElementorPopupLocation',
93062220
);
If anyone could tell me why I need to do this, and why I don't need this in the twentytwenty theme, I'd be glad to accept that as an answer, provided I can use the advice to "fix" my theme.

Why am I not able to see my new image sizes in gutenberg image size list

I have seen several similar questions, but none of them seem to resolve my issue.
I have customised the default thumbnail size and tried to set some custom image sizes, but they are not showing in the Gutenberg image size options - even after clearing, re-generating and re-adding images.
The thumbnail size has updated correctly though.
Below is the code used in my function.php
function set_custom_image_sizes() {
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 600, 330, true );
if ( function_exists( 'add_image_size' ) ) {
add_image_size('hero', 1680, 837, true);
add_image_size('person', 800, 800, true);
}
}
add_action( 'after_setup_theme', 'set_custom_image_sizes' );
function create_custom_image_sizes($sizes){
return array_merge( $sizes, array(
'hero' => __('Hero Image'),
'person' => __('Person Image')
));
}
add_filter('image_size_names_choose', 'create_custom_image_sizes');
The answer in this case is to realise that images in the media library also need to be regenerated even if they have not been added to a page. To prevent the need for re-uploading all images I use a plugin called "Regenerate Thumbnails" to update all the images in the library.
Once installed the regenerate option is available in the "Tools" menu

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

remove image sizes from media uploader box

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.

Hide or remove comments box from wordpress pages

I am developing a plugin everything is going fine but there is a problem.
How can I hide or remove the comments box? I lost many hours but could not develop the right script. My current script is this:
add_filter( 'comments_template', 'remove_comments_template_on_pages', 11 );
function remove_comments_template_on_pages( $file ) {
if ( is_page() )
comments_template('', true);
}
I don't know how to develop this script. Any help could lead me to complete my plugin.
Add the below code to you functions.php file.
add_action('init', 'remove_page_feature');
function remove_page_feature() {
remove_post_type_support( 'page', 'comments' );
}
And now provide a check before the comments template is executed, as below:
if ( post_type_supports( 'page', 'comments' ); )
comments_template('', true);
}
Note: Using the above code will disable comments on pages.

Resources