forked from vincentorback/clean-wordpress-admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimages.php
65 lines (53 loc) · 1.69 KB
/
images.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
/**
* Set default image attachment options
*
* @link https://developer.wordpress.org/apis/handbook/options/
*/
add_action(
'after_setup_theme',
function () {
// Remove default link
if ( get_option( 'image_default_link_type' ) !== 'none' ) {
update_option( 'image_default_link_type', 'none' );
}
// Remove default alignment
if ( get_option( 'image_default_align' ) !== 'none' ) {
update_option( 'image_default_align', 'none' );
}
// Set default size
if ( get_option( 'image_default_size' ) !== 'large' ) {
update_option( 'image_default_size', 'large' );
}
}
);
/**
* Remove srcset on images
*
* @link https://developer.wordpress.org/reference/functions/wp_calculate_image_srcset/
*/
add_filter( 'wp_calculate_image_srcset', '__return_false' );
/**
* Remove lazy loading
*
* @link https://developer.wordpress.org/reference/hooks/wp_lazy_loading_enabled/
*/
add_filter( 'wp_lazy_loading_enabled', '__return_false' );
add_filter( 'wp_lazy_loading_enabled', '__return_false', 'img' ); // disable only on img elements
add_filter( 'wp_lazy_loading_enabled', '__return_false', 'iframe' ); // disable only on iframe elements
/**
* Remove size attributes from images
*
* @param String $html
*/
if ( ! function_exists( 'remove_size_attributes' ) ) {
function remove_size_attributes( $html ) {
return preg_replace( '/(width|height)="\d*"/', '', $html );
}
// Remove size attributes from thumbnail images
add_filter( 'post_thumbnail_html', 'remove_size_attributes' );
// Remove size attributes in the editor
add_filter( 'image_send_to_editor', 'remove_size_attributes' );
// Remove size attributes from the_content
add_filter( 'the_content', 'remove_size_attributes' );
}