Questions tagged [post-thumbnails]
Post Thumbnail is a theme feature introduced with Version 2.9. Thumbnail is an image that is chosen as the representative image for Posts, Pages or Custom Post Types.
1,607
questions
71
votes
5
answers
138k
views
How do I set a featured image (thumbnail) by image URL when using wp_insert_post()?
While looking through the function reference entry for wp_insert_post(), I noticed that there's no parameter in the array it requires which will allow me to set the 'Featured Image' for a post, ...
42
votes
3
answers
78k
views
How come Featured Image isn't showing up in my Custom Post Type?
I have thumbnail support added with the following in my functions.php
// Add Thumbnail Support
add_theme_support('post-thumbnails');
set_post_thumbnail_size( 140, 140, true );
And I create the ...
36
votes
6
answers
169k
views
How to get image title/alt attribute?
In my white theme, there is no alt attribute configured for the home slider post. I added the alt text for the image through the media library interface. I added the following code to display the alt ...
36
votes
4
answers
29k
views
Filter to remove image dimension attributes?
I'm working on a site based on a fluid width css template which sets a max-width on images to the width of the column containing them, and I need to remove the inline width and height dimension ...
34
votes
6
answers
82k
views
How do I get only the image URL from the_post_thumbnail()?
I want to know how to get just the image URL from the_post_thumbnail(). The default output of the_post_thumbnail() is:
<img width="800" height="533" src="http://example.com/...
33
votes
8
answers
7k
views
User-friendly cropping of post thumbnails?
Is there a way to let my users define the crop area of a post thumbnail? The thumbnails always are existing post attachments, I would rather not create an extra attachment per thumbnail.
The post ...
30
votes
6
answers
207k
views
How to Fix HTTP Error When Uploading Images?
I am using WordPress 3.4.1 on Ubuntu 12.04 using Apache and PHP 5.3.X
When I login to the dashboard and add a new post. Then try uploading an image to set as a featured image, I get a red box with a ...
26
votes
4
answers
108k
views
Add class name to post thumbnail
I'm using post thumbnails to link to a page.
Is it possible to add a class name to the post thumbnail image.
<li><a href="<?php the_permalink(); ?>" ><?php the_post_thumbnail(); ...
21
votes
3
answers
69k
views
How do you add thumbnail support for custom post types?
the thumbnail support is working for post, but I have another post type called product and it is not working for this. I am trying: add_theme_support( 'post-thumbnails', array( 'post', 'product' ) );
...
21
votes
5
answers
18k
views
How can I make add_image_size() crop from the top?
I have a series of posts, all with featured images, but I need to be able to customise the crop top right corner. In this instance, I need them to be cropped from top right, but it would be useful to ...
21
votes
6
answers
26k
views
No Thumbnails Generated
I setup WordPress on my own server and it's up and running...one thing that I have noticed is that WordPress doesn't generate any images I upload. Usually when I upload an image through WordPress it ...
19
votes
10
answers
25k
views
How to disable WordPress from creating thumbnails?
I've been looking around the net for a long time on how to disable WordPress from creating multiple thumbnails.
I've seen in most tutorials to set all the images to 0 in the media section. I have ...
19
votes
3
answers
13k
views
add_image_size() for specific Post Types
set_post_thumbnail_size( 80, 80, true ); // true for all post types
Suppose I have two post types in play on my blog: Post, Video and Product. I may want a 80x80 image size for my posts, but 100x100 ...
18
votes
8
answers
38k
views
Stop wordpress from hardcoding img width and height attributes
I'm wondering if there's a simple way top stop WordPress automatically hardcoding featured image height and width attributes, other than using regex...
As I'm using a flexible grid for my project (...
18
votes
2
answers
7k
views
How to retrieve image from URL and set as featured image/post thumbnail
Given a Vimeo ID, I can retrieve a thumbnail from the video via Vimeo Simple API. Rather than call the API every time my page loads I want to set the image as the post thumbnail using the save_post ...
17
votes
2
answers
15k
views
Programmatically get images by URL and save in uploads folder
I am involved in a large migration from another CMS to WordPress. We have a copy of the database and have worked out how to extract the content and programmatically create WordPress posts from it ...
17
votes
2
answers
34k
views
Query posts only with featured image
I want to query 6 posts, but only those which have a featured image attached. I am using meta_key method for this with WP_Query as such:
$args = array(
'post_type' => 'post',
'meta_key' =&...
16
votes
4
answers
31k
views
How do you remove hard coded thumbnail image dimensions?
How can I remove the width and height attributes from the post_thumbnail when inserting with <?php the_post_thumbnail(); ?>?
<img width="800" height="533" src="http://domain.com/wp-content/...
16
votes
1
answer
23k
views
How to get featured image's width and use elsewhere in template?
I'm wondering if it's possible in the single.php template to use the width of the post's featured image elsewhere in the page.
What I'm trying to do is add a div element on the page with the same ...
16
votes
3
answers
35k
views
How to set featured image to custom post from outside programmatically
I am trying to fetch and insert images outside the wordpress environment to a custom post via PHP.
How to move/upload that image to wordpress upload directory year date folder format just like ...
16
votes
7
answers
27k
views
How do you get the post thumbnail size?
I know how to set the size of a post thumbnail image using the WP Admin Media Settings or using this function:
set_post_thumbnail_size( 150, 150 )
But how would one get the image width and height ...
16
votes
1
answer
12k
views
Setting a post's featured image from an embedded YouTube video
If I create a post that has an embedded YouTube video in it (so all I do is paste the YouTube URL into the post and let Wordpress automatically embed it for me), is there a way to have the thumbnail ...
15
votes
6
answers
10k
views
Minimum Dimensions Requirement for Featured Image?
I am creating a baseball website with multiple Authors. From past experience, no matter how well you know someone personally, it doesn't mean they will follow or even read your instructions.
That ...
14
votes
2
answers
17k
views
set_post_thumbnail_size vs add_image_size
What is the difference between set_post_thumbnail_size and add_image_size? Is set_post_thumbnail_size for all images, and add_image_size for sizing images individually?
Thanks.
14
votes
3
answers
32k
views
How to get all featured image sizes and their URLs?
Is there a standard way to get all the registered sizes of the featured images?
One can register different sizes with add_image_size().
What I need, is to get all the sizes of a featured image of a ...
14
votes
4
answers
6k
views
Generate Thumbnails only for Featured Images
I would like to know if there is a simple way (custom code or plugin) to create thumbnail sizes only for images that I intend to use as featured images (index.php, archive.php, etc.) , but not for the ...
13
votes
2
answers
9k
views
The the_post_thumbnail without srcset?
The WordPress 4.4 adds multiple image sizes with srcset when using the_post_thumbnail function. Is it possible to get only one image size without srcset ?
I understand that it is possible to add a ...
12
votes
6
answers
39k
views
Get the first image from post content (eg.: hotlinked images)
I am using this code directly from the codex.
function echo_first_image ($postID)
{
$args = array(
'numberposts' => 1,
'order'=> 'ASC',
'post_mime_type' =>...
12
votes
1
answer
3k
views
How to disable generation of default image sizes for some custom post types?
I used custom post type, where 'thumbnail', 'medium' and 'large' sized not required. I need to disable this sizes and create function or plugin, where i can set, which image size is required for each ...
12
votes
1
answer
23k
views
How to Dynamically Resize WordPress Image On-The-Fly (custom field/theme option)
So - at a client's request, I am in need of being able to resize an image not the standard WordPress way... but from an image pulled-in from a theme option. I can't simply use the custom_header area, ...
11
votes
3
answers
8k
views
WordPress adding scaled images that don't exist (1536x1536 and 2048x2048)
I'm building a theme in _S and using native Gutenberg blocks.
I have the following code via my functions.php file to set my image sizes:
add_theme_support( 'post-thumbnails' );
add_image_size( '...
11
votes
5
answers
41k
views
Can I set a default featured image for a category?
I'm setting up a site with a theme that takes advantage of the "featured image" feature of WordPress. Since my end users are not the most tech saavy in the world, I'd like to set things up so that the ...
11
votes
3
answers
32k
views
How do I change/modify the_post_thumbnail(); html output?
I'm working on building out a custom theme and have been struggling with this one for a bit. I am trying to modify the HTML output of the_post_thumbnail(); function. I need to do this because I am ...
10
votes
4
answers
20k
views
Post featured image column on admin post list page
I have a client site which accepts images from users as posts. For moderation, we are opening each draft post which obviously takes a lot of time if a hefty amount of images are moderated.
So, Is ...
10
votes
3
answers
13k
views
How to add post featured image to RSS item tag?
I am able to add a post featured image to the RSS feed like so:
function insertThumbnailRSS($content) {
global $post;
if(has_post_thumbnail($post->ID)){
$content = ''....
10
votes
2
answers
52k
views
featured image as background image on pages
I'm adding a featured image on my page through the dashboard and I want to use it as a background image on the container div of the page.
I want to apply the background image through css, so I am ...
10
votes
4
answers
13k
views
Download an image from a webpage to the default uploads folder
I am writing a custom theme/plugin in which I need to download images programatically from certain webpages to the upload folder and then insert them as part of the post.
So, I was able to find the ...
10
votes
9
answers
12k
views
How to automatically add rounded corners to thumbnails?
I want to created automatically rounded corner thumbnails for a particular project I'm working on, using something like this: http://webdeveloperplus.com/php/create-thumbnail-images-with-rounded-...
10
votes
3
answers
16k
views
How do I regenerate thumbnails?
I just got a new theme and am trying to regenerate thumbnails. I'm having trouble though. I tried using the AJAX Thumbnail Rebuilder but for 5 hours it just said reading attachments. Then I tried the ...
10
votes
3
answers
42k
views
wp_get_attachment_image_src always returns full-sized image
https://codex.wordpress.org/Function_Reference/wp_get_attachment_image_src#Parameters leads me to believe wp_get_attachment_image_src( $thumb_id, array(100, 100) )[0] would return a 100x100 thumbnail, ...
10
votes
1
answer
11k
views
the_post_thumbnail responsive srcset not populating with custom image size
I am trying to use the new responsive images feature in Wordpress 4.4 but I keep running into a particular problem when trying to use the_post_thumbnail with a custom image size. It seems I cannot ...
10
votes
7
answers
10k
views
Display thumbnail only if requested size exists
When I use the functions that get and output the post thumbnail, they will display the requested thumbnail in the size you specify, but if this size doesn't exist they will display the thumbnail in ...
9
votes
4
answers
50k
views
Post thumbnail alt title
i wanted to know if "Alt title" is needed like "Title" for post thumbnails and how can add it in my related post query... i'm using this code to get the post thumbnail:
<div class="td-module-thumb"...
9
votes
4
answers
13k
views
Remove the Featured Image Meta Box
How can I remove the Featured Image meta box? I've tried using the remove_meta_box function and specifying the boxes ID but it doesn't seem to work like it does for the other native meta boxes.
...
9
votes
1
answer
23k
views
Upload post thumbnail from the front end
We would like users to be able to upload the post thumbnail when editing posts. How would this be done. I would imagine it would make use of the ajax functions of wordpress.
Any ideas,
Marvellous
9
votes
8
answers
7k
views
Delete original image - keep thumbnail?
I'm using a lot of thumbnails but never the original file. To save space, I'd like to prevent the original from being saved on disk but only keep a thumbnail of 100px. How can I do this?
Thanks,
...
9
votes
4
answers
5k
views
What's the best way to use the Featured Image for responsive web design?
I have a brilliant idea and since WordPress already takes care of some of the work, I just need to find a good method to make this work.
I am working on a project that needs to be responsive to all ...
9
votes
2
answers
4k
views
Set custom name for generated thumbnails
Is there any filter available to set the naming convention of those auto generated thumbnails?
Something like this:
thumbnail_150x150.jpg -> thumbnail-s.jpg
thumbnail_300x300.jpg -> thumbnail-m.jpg
...
8
votes
2
answers
27k
views
Get Featured Image via direct sql query
I know you can use the wordpress methods for getting a featured image, however with this particular project I need to get the featured image via mysql query. Can anyone point me in the right direction....
8
votes
5
answers
19k
views
Get featured image on Blog Index
I've been trying to use the "featured image" from the home (the blog index) with no luck. It's working for every single page, but it's not working for the home.
The code looks something like this:
//...