Last active
February 22, 2024 12:12
-
-
Save kimwhite/fe3762d1c61962f80e24a72c316a200b to your computer and use it in GitHub Desktop.
Change the Default Avatar Size when using the Basic Avatar Shortcode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* by default the WordPress Avatar default size is 96x96 | |
* this code will change default WP size for page 56 (you can change this) | |
* you can choose a size that is available. | |
* check your Media settings in WordPress Settings Area. | |
*/ | |
function my_get_avatar( $avatar, $id_or_email, $size, $default, $alt ) { | |
// Check if we're on page 56 | |
if (is_page(56)) { | |
// Define the new default size | |
$new_default_size = 150; // For example, 150x150 pixels | |
// Check if the size is already specified and is different from the new default size | |
if ($size !== $new_default_size) { | |
// Replace the size in the args array | |
$args = array( | |
'size' => $new_default_size, | |
'default' => $default, | |
'alt' => $alt | |
); | |
// Rebuild the avatar tag with the new size without causing recursion | |
$avatar = get_avatar( $id_or_email, $new_default_size, $default, $alt, $args ); | |
} | |
} | |
return $avatar; | |
} | |
add_filter( 'get_avatar', 'my_get_avatar', 10, 5 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment