How to get attached image alt text in media.php?

In the answers to this forum post is mentioned that $alt = get_post_meta($attachment_id, ‘_wp_attachment_image_alt’, true); will get the job done for you. Maybe you should give that a try and look at the further information there.

Function to get custom post image URL

Can you show us what the cp_get_image_url() function does? Is it from a plugin or theme? Is the image uploaded to the Featured Image or a Custom Field? Without knowing what that function is actually doing, the best I could come up with is this: <?php $media = get_attached_media(‘image’); foreach($media as $m) { $mee = … Read more

If image width bigger than height [duplicate]

Use wp_get_attachment_metadata(). Using your example: $img_data = wp_get_attachment_metadata( $attachment_id ); $w = $img_data[‘width’]; $h = $img_data[‘height’]; if ($w > $h) { $class = “col-sm-12”; } else { $class = “col-sm-6”; } Though, to get the attachment ID, you’ll either have to put a filter that acts on every image or create a loop that uses … Read more

Full width images within post content

I believe you’ll want to set the image as a background image on the div (with inline CSS). In your template’s PHP you can use the following to get the URL to the full-sized featured image (within the Loop, of course): $image_url = wp_get_attachment_url( get_post_thumbnail_id( $post->ID ) ); Then to assign this image as the … Read more

While doing a bulk upload the Media Images are showing blank?

Your $loopimage field in your spreadsheet only has the filename and not the file path, but wp_insert_attachment needs the full pathname in the 2nd argument. Additionally though, if you have uploaded all of these images using the Media Manager interface then they will already be stored as attachments. You’d be better off using the file … Read more