How to get the URL of a each custom image size of a featured image

So, I finally noticed that what I was doing, was returning an array, and that I needed the [0] of that array. The code is on the ugly side, but it works. <?php $thumb_id = get_post_thumbnail_id(); $small_screen = wp_get_attachment_image_src($thumb_id,’small-screen’, true); $medium_screen = wp_get_attachment_image_src($thumb_id,’medium-screen’, true); $large_screen = wp_get_attachment_image_src($thumb_id,’large-screen’, true); $extra_large_screen = wp_get_attachment_image_src($thumb_id,’extra-large-screen’, true); ?> – <div … Read more

Set Featured Image Based on Custom Field

global $wpdb; $children = get_posts(‘post_type=event&numberposts=1’); foreach ($children as $child) { $origParentID = get_post_meta($child->ID, ‘mainpictureid’, true); $parsed_url = explode( parse_url( WP_CONTENT_URL, PHP_URL_PATH ), ‘http://localhost/wp-content/uploads/2015/08/’.$origParentID.’.jpg’ ); $attachment = $wpdb->get_col( $wpdb->prepare( “SELECT ID FROM {$wpdb->prefix}posts WHERE guid RLIKE %s;”, $parsed_url[1] ) ); set_post_thumbnail( $child->ID, $attachment[0]); }

Featured images not showing up

Finally found the issue: I was using a filter in my site specific plugin to remove image attributes. Somehow it also deleted the full image URL. add_filter( ‘post_thumbnail_html’, ‘remove_img_attributes’, 10 ); Removing that filter solved the issue.

Allow ‘Set featured images’ to select multiple images

Its certainly not a few liner code. So its better to use a Feature Gallery plugin. I just tried that which works perfectly fine and you can use below code to get the images in Featured Gallery. <?php $galleryArray = get_post_gallery_ids($post->ID); foreach ($galleryArray as $id) { ?> <img src=”https://wordpress.stackexchange.com/questions/205062/<?php echo wp_get_attachment_url( $id ); ?>”> <?php … Read more

Adding a class to certain featured images

One option would be to do it client-side via javascript – set up some javascript to run after the page loads and cycle through all featured images that are on the page, get their dimensions and then add the class as need be. You can use the img.naturalWidth and img.naturalHeight parameters of the image element, … Read more

How to show only 2nd featured img on home/blog

Edit: This need to be placed into your template. if( class_exists(‘Dynamic_Featured_Image’) ) { //if you only want to show 2nd featured image you can do if (isset($featured_images[1])) { $image = $featured_images[1]; echo “<a href=”https://wordpress.stackexchange.com/questions/208168/{$image[“full’]}’>”; echo “<img src=”https://wordpress.stackexchange.com/questions/208168/{$image[“thumb’]}’ alt=”Dynamic Featured Image” />”; echo “</a>”; } }

Featured Image, and Image in post

on the template of the page that you are trying to pull the first image on,(if its the post itself, then single.php) you could use the following code instead of the_post_thumbnail function echo_first_image( $postID ) { $args = array( ‘numberposts’ => 1, ‘order’ => ‘ASC’, ‘post_mime_type’ => ‘image’, ‘post_parent’ => $postID, ‘post_status’ => null, ‘post_type’ … Read more