The WP Customizer’s WP_Customize_Image_Control returns the attachment’s URL, but I need the ID because I want to output the image like this:

echo wp_get_attachment_image( $user_logo_id, 'riiskit-user-logo' );

The reason for this is because I want the logo to be compatible with the WP Retina 2x plugin. That’s why I’m using the thumbnail-sizing above. This way, the user only has to upload one big image and everything else will be taken care of by the code.

I’ve already tried all the different attachment_src_to_id functions out there but none of them works and only returns null or false. This for instance

Even when I type the URL manually as a parameter, it still returns negative.

However when I type the ID manually inside wp_get_attachment_image, it shows as expected.

Have something changed in WP v3.9 that causes these functions to return false?

Perhaps there is some way to extend the Customizer’s image control to receive the attachment ID?

Any ideas? 🙂

2 Answers
2

This is very old, but for someone coming here via search

WP_Customize_Media_Control control in WP since 4.2 give you the attachment id.

Ref: https://make.wordpress.org/core/2015/07/16/new-customizer-media-controls-in-4-3-and-4-2/

Leave a Reply

Your email address will not be published. Required fields are marked *