Add theme support for post thumbnails

What add_theme_support( ‘post-thumbnails’, array( ‘products’ ) ); did is: it added the support for the post-thumbnail feature, and with the second parameter you fixed the feature support to only post_type = ‘products’. But it actually saying: Ok, load all the necessary things to register a Post Thumbnail — you’re actually introducing ‘Post Thumbnail’ to WordPress. … Read more

Set (featured) thumbnail for post?

Perhaps use set_post_thumbnail()? (Codex ref.) EDIT To get the attachment ID using the Post ID: // Associative array of attachments, as $attachment_id => $attachment $attachments = get_children( array(‘post_parent’ => $post->ID, ‘post_status’ => ‘inherit’, ‘post_type’ => ‘attachment’, ‘post_mime_type’ => ‘image’, ‘order’ => ‘ASC’, ‘orderby’ => ‘menu_order ID’) ); $attachment = $attachments[0]; // ID of your single, … Read more

Displaying a featured image (only img url) as the img src?

Here are the functions you need to be aware of: http://codex.wordpress.org/Function_Reference/get_post_thumbnail_id http://codex.wordpress.org/Function_Reference/wp_get_attachment_url http://codex.wordpress.org/Function_Reference/wp_get_attachment_image_src http://codex.wordpress.org/Function_Reference/wp_get_attachment_image Example sans size: echo wp_get_attachment_url(get_post_thumbnail_id()); Example with size: $image = wp_get_attachment_image_src(get_post_thumbnail_id(), ‘large’); echo $image[0]; //as HREF in your A tag You can grab all of the gallery images as follows: $args = array( ‘order’=> ‘ASC’, ‘post_mime_type’ => ‘image’, ‘post_parent’ => $post->ID, … Read more

Fallback default image when there is no featured image

Method 1: Set Default Fallback Image for Post Thumbnails Using Plugin This method is easier and recommended for all users. First thing you need to do is install and activate the Default Featured Image plugin. https://wordpress.org/plugins/default-featured-image/ Method 2: Add Fallback Image as Post Thumbnail Manually Your theme’s images folder is located inside /wp-content/themes/yur-theme/ folder. If … Read more

Can’t Display Featured Image in RSS Feed

By default, RSS won’t display. You have to use RSS2. However this will help you. Paste it in your functions.php: function insert_thumbnail_into_feed() { global $post; if ( has_post_thumbnail( $post->ID ) ){ // replace thumbnail with yours $content=”<p>” .get_the_post_thumbnail( $post->ID, ‘thumbnail’ ) .'</p>’; } // get post content and replace feed content with // you can … Read more

Is it possible to prevent users from uploading small images?

Here you go: if(!current_user_can(‘delete_others_posts’)){ /*Handling wp media uloads*/ add_filter(‘wp_handle_upload_prefilter’,’lets_handle_img_width’); function lets_handle_img_width($file) { $img = getimagesize($file[‘tmp_name’]); $width = $img[0]; if ($width < 350){ $file[‘error’] = “Image is small too small. Get something of width more than 350px.”; } return $file; } } Check official documentation about wp_handle_upload_prefilter.

How to change _wp_attachment_metadata specific value in SQL?

You could do this via PHP instead of SQL, just get the existing metadata and change what you need to, it will handling the serializing for you: $newwidth=”250″; // or whatever it is $attachments = get_posts(array(‘post_type’=>’attachment’); foreach ($attachments as $attachment) { $id = $attachment->ID; $metadata = wp_get_attachment_metadata($id); $metadata[‘width’] = $newwidth; wp_update_attachment_metadata($id,$metadata); } But really, you … Read more

No srcset for hard-cropped thumbnails

To show a srcset, there must be multiple image sizes of the same aspect ratio. When you set your thumbnail to hard crop without creating any other image sizes you are ensuring that there won’t be a srcset. You might find my answer here helpful. Briefly, in your case, adding this line: add_image_size ( ‘double-size’, … Read more