Opened 8 years ago
Last modified 12 days ago
#37972 new defect (bug)
Image size (height/width) arguments are not used in output for custom_logo
Reported by: | BinaryKitten | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | 4.6 |
Component: | Themes | Keywords: | has-patch |
Focuses: | Cc: |
Change History (3)
This ticket was mentioned in Slack in #themereview by joyously. View the logs.
7 years ago
This ticket was mentioned in PR #1423 on WordPress/wordpress-develop by paulschreiber.
3 years ago
#2
- Keywords has-patch added
5 weeks ago
#3
To fetch the height and width from the custom logo settings in WordPress and pass them as a size parameter to wp_get_attachment_image()
, you can use the following approach:
- Get the Custom Logo ID: Use
get_theme_mod( 'custom_logo' )
to retrieve the custom logo ID. - Get the Image Metadata: Use
wp_get_attachment_metadata()
to fetch the logo’s width and height. - Pass Dimensions to
wp_get_attachment_image()
: Once you have the dimensions, pass them in thesize
parameter when callingwp_get_attachment_image()
.
Here’s an example code snippet:
// Get the custom logo ID
$custom_logo_id = get_theme_mod( 'custom_logo' );
// Check if a custom logo is set
if ( $custom_logo_id ) {
// Get the logo metadata
$logo_metadata = wp_get_attachment_metadata( $custom_logo_id );
// Extract width and height if available
$width = $logo_metadata['width'] ?? '';
$height = $logo_metadata['height'] ?? '';
// Pass width and height to wp_get_attachment_image as an array
echo wp_get_attachment_image( $custom_logo_id, [ $width, $height ] );
}
<sub><sup style="font-size: 0.1em;">.</sup></sub>
This code checks if a custom logo exists, retrieves its dimensions, and then passes those dimensions as an array to wp_get_attachment_image()
. This approach ensures the custom logo appears at its correct size.
Note: See
TracTickets for help on using
tickets.
Fetch the height and width from the custom logo settings. If present, pass them in as a size parameter to wp_get_attachment_image().
Trac ticket: https://core.trac.wordpress.org/ticket/37972