How to retrieve alt attribute for an attachment (uploaded image)?
I haven’t actually tested this, but came across the following code on my travels. Might this help? get_post_meta($attachment_id, ‘_wp_attachment_image_alt’, true)
I haven’t actually tested this, but came across the following code on my travels. Might this help? get_post_meta($attachment_id, ‘_wp_attachment_image_alt’, true)
Here’s something I wrote because my clients were using very high quality pngs, when they could be more lossy jpgs for web. Note this still preserves the original image, only changes the thumbnails. Add this to your functions.php <?php //Force PNG Thumbnails into JPGs add_filter(‘wp_generate_attachment_metadata’,’force_png_to_jpg’); function force_png_to_jpg($image_data) { $sizes = array(‘thumbnail’,’medium’,’large’); $upload_dir = wp_upload_dir(); $file … Read more
This should do it for you. If you’re calling it in a function, you’ll of course need to ensure $wpdb is the global. $required_number_of_attatchments = 3; $posts = $wpdb->get_col( $wpdb->prepare( “SELECT posts.ID FROM %s AS posts INNER JOIN ( SELECT MAX(post_modified) AS modified, post_parent FROM %s WHERE post_type=”attachment” AND post_parent > 0 GROUP BY post_parent … Read more
You might have better luck using wp_get_attachment_url( $id ) rather than wp_get_attachment_image(). Take a look at the WordPress codex for the call.
WordPress has a function, get_allowed_mime_types, which will return all allowed types. We can filter this list and exclude any types containing image, then query for all remaining types by passing them as a comma separated list to post_mime_type. This may not be the most efficient way to do it, you may be better off filtering … Read more
You can do this by adding this function to your funcitons.php file. function my_get_image_size_links() { /* If not viewing an image attachment page, return. */ if ( !wp_attachment_is_image( get_the_ID() ) ) return; /* Set up an empty array for the links. */ $links = array(); /* Get the intermediate image sizes and add the full … Read more
Not really, attachments are still not “full post types”. Manny Flerumond hints this quite well in this thread: Was thinking about this the past few days: currently any media files uploaded to a WordPress site defaults to the post status of inherit, which is a holdover to when media attachments were just that. Media was … Read more
Don’t know if that will solve all your problems, but: Generally nicely formatted code is easier to debug. E.g. your code is missing the closing brace. Besides it is better to write if/else(if) statements with braces. Nice indentation helps too. I’d suggest reading the WordPress – PHP Coding Standards. Regarding your code: As noted at … Read more
I found the solution to add that attribute to the img tag with this function: add_filter(‘the_content’,’new_content’); function new_content($content) { $content = str_replace(‘<img’,'<img data-qazy=”true”‘, $content); return $content; }
Attachments in WP are stored as posts of type attachment which reference files physically stored in the uploads folder. This is why if you FTP a file into the uploads folder it doesn’t appear in the media library. This means the media library is a post archive, much like other post archives in the admin … Read more