Add "Feature Image" Option on add new post - wordpress

I want to add an option to add feature image on add new post page like the image below.
How can I do it?

You need to use the wordpress function add_theme_support( 'post-thumbnails' );
Just add that line of code in your wordpress functions, and it will allow you to do that.
Read more about it here: http://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails
Hope that helps!
UPDATE: here is what I use in my functions.php. It creates re-sized versions of your uploaded images in your uploads folder. very useful:
// post thumbnail support
if ( function_exists( 'add_image_size' ) ) add_theme_support( 'post-thumbnails' );
if ( function_exists( 'add_image_size' ) ) {
add_image_size( 'featured-thumb', 282, 158, true );
}

Related

Custom Feature Image Size Issue WordPress

The given page is a blog archive page that lists recent posts.
https://petcarepicks.com/
I want the featured image thumbnail on this page to load the same file size as it display (360px by 180px). I added the given code in functions.php of the theme, but it is still not working. It loads the old file of 408 x 204 size and display on new dimensions.
add_image_size('new-few-img', 360, 180,true);
the_post_thumbnail('new-few-img')
The new image size is registered, and the file appears in directory after regenerating the thumbnails. However, on front end it still loads the old dimensions and displays new dimensions (Forced by CSS).
I also tried using below line;
if ( has_post_thumbnail() ) {
the_post_thumbnail( 'new-few-img' );
}
or
set_post_thumbnail_size(360,180,true);
or
if ( function_exists( 'add_theme_support' ) ) {
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 360, 180, true );
}
Please help me resolve the issue.
Add below code into you function.php file.
function register_new_thumbnail() {
add_theme_support( 'post-thumbnails' );
add_image_size('new-few-img', 360, 180,true);
}
add_action( 'after_setup_theme', 'register_new_thumbnail' );
Now your new thumbnail size is registered and will work on only new images. To crop your already used image you need a plugin which will help you to regenerate this thumbnail size.
https://wordpress.org/plugins/regenerate-thumbnails/
https://wordpress.org/plugins/regenerate-thumbnails-advanced/
I hope this may help your issue.

Why am I not able to see my new image sizes in gutenberg image size list

I have seen several similar questions, but none of them seem to resolve my issue.
I have customised the default thumbnail size and tried to set some custom image sizes, but they are not showing in the Gutenberg image size options - even after clearing, re-generating and re-adding images.
The thumbnail size has updated correctly though.
Below is the code used in my function.php
function set_custom_image_sizes() {
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 600, 330, true );
if ( function_exists( 'add_image_size' ) ) {
add_image_size('hero', 1680, 837, true);
add_image_size('person', 800, 800, true);
}
}
add_action( 'after_setup_theme', 'set_custom_image_sizes' );
function create_custom_image_sizes($sizes){
return array_merge( $sizes, array(
'hero' => __('Hero Image'),
'person' => __('Person Image')
));
}
add_filter('image_size_names_choose', 'create_custom_image_sizes');
The answer in this case is to realise that images in the media library also need to be regenerated even if they have not been added to a page. To prevent the need for re-uploading all images I use a plugin called "Regenerate Thumbnails" to update all the images in the library.
Once installed the regenerate option is available in the "Tools" menu

Wordpress - Responsive images - remove sizes

Sometime ago I added a couple of additional image formats to Wordpress in order to fine-tune my responsive display. I added those lines to functions.php:
add_image_size( "maximal", "1900" );
add_image_size( "desktop", "1400" );
add_image_size( "tablet", "900" );
add_image_size( "smalltablet", "700" );
add_image_size( "mobile", "500" );
add_theme_support( 'post-thumbnails' );
I release I was too greedy because I'm not using most of those formats now and I would like to remove some of them. To do so I basically commented the image formats that I wanted to get rid of but from what I see, all srcset attributes are still listing them in my code.
Is there a way to tell Wordpress to stop adding those formats in srcset ? I thought of using a regex to get rid of them but that generates additional processing to the page.
Thanks
Laurent
To make sure that these images' sizes is unregistered use this:
remove_image_size( "maximal" );
Then use these filters to clean the current images from these sizes:
// Remove the calculated image sizes
add_filter( 'wp_calculate_image_sizes', '__return_false' );
// Remove the calculated image sizes
add_filter( 'wp_calculate_image_srcset', '__return_false' );
// Clean image attrs
add_filter( 'wp_get_attachment_image_attributes', 'unset_image_sizes');
function unset_image_sizes() {
if( isset( $attr['sizes'] ) )
unset( $attr['sizes'] );
if( isset( $attr['srcset'] ) )
unset( $attr['srcset'] );
}
I hope this helps.

Define a new cropping image size in Wordpress

Inside Wordpress, I need to generate and create inside the upload folder a new cropping image size that has:
width=205px
height=120px
Inside my function.php here is my code:
// Call function on after setup
add_action( 'after_setup_theme', 'theme_setup_img' );
function theme_setup_img() {
add_theme_support( 'post-thumbnails' );
add_image_size('search-thumb', 205, 120, true );
// set_post_thumbnail_size( 205, 120, true );
}
However, no new image-sizes have been created inside the upload folder (only default WP sizes). Any solution?
Note: I'm using the default theme and the latest WP version
Your code looks correct. Mine is slightly different and I know it works:
if (function_exists('add_theme_support'))
{
// Add Thumbnail Theme Support
add_theme_support('post-thumbnails');
add_image_size('large', 700, '', true); // Large Thumbnail
add_image_size('medium', 250, '', true); // Medium Thumbnail
}
This was taken from the HTML5 Blank Theme by Todd Motto. Gerald also mentioned writing a script to re-render but there's a great plugin for that called Regenerate Thumbnails that does the same thing.
This might be due to you calling the new size inside the "after_setup_theme" action... I use the following code:
// Add custom image sizes
if( function_exists( 'add_image_size' ) ) {
add_image_size( 'search-thumb', 205, 120, true );
}
And it works every time... if it's inside the functions.php file, you don't need an action or hook to make it work.
Also, you can add this to functions.php to make your custom sizes show up in the drop down menus when inserting images into pages/posts/where ever:
// Functions to add custom image sizes to the media library thickbox area
// and put them into drop down
function my_insert_custom_image_sizes( $sizes ) {
// get the custom image sizes
global $_wp_additional_image_sizes;
// if there are none, just return the built-in sizes
if ( empty( $_wp_additional_image_sizes ) )
return $sizes;
// add all the custom sizes to the built-in sizes
foreach ( $_wp_additional_image_sizes as $id => $data ) {
// take the size ID (e.g., 'my-name'), replace hyphens with spaces,
// and capitalise the first letter of each word
if ( !isset($sizes[$id]) )
$sizes[$id] = ucfirst( str_replace( '-', ' ', $id ) );
}
return $sizes;
}
add_filter( 'image_size_names_choose', 'my_insert_custom_image_sizes' );
You will need a plugin (I use AJAX Thumbnail Rebuild) to resize old images already uploaded before this code was implemented.
The problem here was the "Dynamic Image Resizer" plug-in.
It was breaking my theme with Wordpress 4.0.

images are cropping automatically in wordpress

i'm working on wordpress with themify parallax theme.there is a option in parallax theme setting to use header gallery.when i choose the images for gallery they are looking blurry.then i noticed that i have uploaded the image(bg04) of size 1024x619 and after checking the page with firebug its showing extra bg04-1024x536.jpg in every image.
Here are my media settings:
Thumbnail size 150x150
Medium size 300x300
Large size 1024x1024
Please guys help me on this.
You can add custom size for thumbnail images
add_image_size( $name, $width, $height, $crop );
or use for getting original image size
get_the_post_thumbnail( $post_id, $size, $attr )
where $size = 'full'
You can something add this to your themes functions.php file to give it custom sizes.
/* Add Post Thumbnails */
if ( function_exists( 'add_theme_support' ) ) {
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 110, 96, true ); // Normal post thumbnails
add_image_size( 'post-image', 350, 350, TRUE ); // Post image
add_image_size( 'news-listing', 140, 140, TRUE ); // News Listing image
add_image_size( 'slider_image', 1070, 378, TRUE ); // Slider image
}
And then to grab the specific sizes you use
$src = grab_featured_img_url('slider-image');
(Sorry if you already knew how to do that, just covering all bases :) )
If you dont want wordpress to crop your images for you, and you've already added them, maybe consider this plugin
https://wordpress.org/support/view/plugin-reviews/manual-image-crop
That will help you set specific sizes and allow you to manually crop images that are done a bit off.

Resources