WordPress Post featured image URL in the header

To answer this one and point to the real problem: As the <head> HTML tag comes far before the actual loop, you’ll need something else than the global $post. get_queried_object(); get_queried_object_id(); The plugin The code is tested and works. As you might want to keep this functionality when switching themes, I’d suggest wrapping it up … Read more

Get image alt attribute just by image URL

Using the function found here, you could add this to your functions.php // retrieves the attachment ID from the file URL function pippin_get_image_id($image_url) { global $wpdb; $attachment = $wpdb->get_col($wpdb->prepare(“SELECT ID FROM $wpdb->posts WHERE guid=’%s’;”, $image_url )); return $attachment[0]; } But to use it, you need the full image URL. $img_url = get_bloginfo(‘url’) . “https://wordpress.stackexchange.com/bc/wp-content/uploads/placeholder-image.png”; if … Read more

Image Quality Thumbnail Compression in WordPress?

(this should be a comment, but my reputation is too low) Setting jpeg_quality will not disable compression because it does not disable processing. JPEGs will be always compressed, and they are almost never lossless, not even at 100 – it does not stand for “100% original quality”. What happens here, is that WordPress’s default image … Read more

A way to change image urls in post to cdn image url?

You can parse via regex for images in the_content; but is always load and slowly. Maybe you change the url of images, after post_save in database or change the current posts inside the database and create an custom CDN. Its the fast way and all caching plugins has the break, that she must parse the … Read more

Getting alt text of featured image

The alt text is stored as post meta on the attachment, and can be retrieved with get_post_meta() combined with get_post_thumbnail_id(): <?php echo get_post_meta( get_post_thumbnail_id(), ‘_wp_attachment_image_alt’, true ); ?> But if you just use the the_post_thumbnail() function then you don’t need to bother, the img tag will be output for you, with the alt text: <?php … Read more

Why can I not view image attachment pages?

From what you’ve described, it sounds like the theme doesn’t have an attachment.php template to handling displaying the actual attachment page. You check on the attachment page, by going to Appearance->Editor, and checking for an attachment.php; however, I believe that answer is incorrect. WordPress should default to displaying the image on the normal blog index … Read more

How to check if user is uploading/setting an image as a featured image?

Determining if an attachment actually is a featured image is easy: get_post_thumbnail_id( get_post() ); which is a convenience function around get_post_meta( get_post()->ID, ‘_thumbnail_id’, true ); It is a bit more complicated if you know nothing than the File name or Url. add_filter( ‘wp_handle_upload_prefilter’, function( $file ) { $url = wp_get_attachment_image_src( get_post_thumbnail_id( get_post() ), ‘post-thumbnail’ ); … Read more

Images in upload folder with hexadecimal names

Testing the plugin provided in this Answer, I just saw that media_handle_sideload generates exactly this pattern, jpeg extension as well (instead of jpg). Following its path through the core, it seems that only the filter wp_handle_upload could be used for dealing with that. But a brief research shows an interesting use of wp_handle_upload_prefilter: Rename files … Read more

Image File Names

Those numeric suffixes are image sizes corresponding to the width/height values in wp-admin->Settings->Media. It is part of the thumbnail system. If the right image manipulation libraries are installed on the server, WordPress will create these different image sizes when you upload an image. The idea is that you can then load appropriately sized images for … Read more

Display latest 12 images from media library

Simply omit the parent value. $args = array( ‘post_type’ => ‘attachment’, ‘post_status’ => ‘published’, ‘numberposts’ => 12, ); Check the documentation for other arguments: Function_Reference/get_posts. Maybe you’d like to use the PHP command shuffle, like shuffle( $attachments );.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)