Wordpress 3.8 add_image_size( ) not working - php

i am trying to create my first wordpress theme and i came now to a problem i can't seem to solve.
Due to the design of the theme, i would like to have featured images on every post, but they would need to be all the same size.
On my functions.php i have enabled the feature images, set a size and even tried to add custom size, but nothing is working as i wanted.
My code looks like this:
function.php:
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 200,200, true);
add_image_size( 'feat', 200, 200, true );
then on my content.php:
<?php the_post_thumbnail('feat'); ?>
The images resize, but they don't crop. It makes the bigger side of the image equal to 200, but still keeps the original aspect ration.
Any ideas of what i'm doing wrong?

Maybe it happens because you had added add_image_size before you uploaded your images.
Try to delete and upload images again or download Regenerate Thumbnails plugin and regenerate all your images in media library.

Related

How to Add Custom post Thumbnails in WordPress Theme without Plugin

On my WordPress website, I have a blog page that contains 4 posts, and each post has an image of size 1080x900 px. I want to show this image as a thumbnail of 350x300px on the WordPress site.
How can I add custom thumbnail size in the function.php file and what is the next step to do?
You can use
add_theme_support( 'post-thumbnails' );
add_image_size( 'custom-size', 350, 300, true );
Images will be available as a thumb in that size after you regenerate media.
For more info: https://developer.wordpress.org/reference/functions/add_image_size/

Crop thumbnail images - add_image_size - Wordpress

I am trying to add a thumbnail crop to images, however I can't get it to work correctly. I have faced similar problems earlier, but wasn't able to solve it.
The page shows the latest posts, and since some of them has different horatio and size, I must use thumbnail crop within functions to make them appear the same size and correct horatio, and not scale them into something different.
This is the code I am using to show latest thumb
<?php if ( has_post_thumbnail() ) { the_post_thumbnail('frontpage_thumb'); } ?>
Within functions.php:
if ( function_exists( 'add_theme_support' ) ) {
add_theme_support( 'post-thumbnails' );
add_theme_support( 'nav-menus' );
}
add_action( 'after_setup_theme', 'mytheme_custom_thumbnail_size' );
function mytheme_custom_thumbnail_size(){
add_image_size( 'frontpage_thumb', 300, 220, array( 'center', 'center' ) ); // Hard crop center
}
The problem
They thumbs resize, but don't crop. See page.
I have tried Regenerate Thumb Plugin, but no result.
Have I misunderstood the "WP cropping"?
The problem appeared to be related with the thumbnails with Wordpress.
To solve the problem I did the following:
Uninstall the thumbnail plugin used
Install another thumbnail plugin
Regenerate

How can i use the uploaded image as featured image in wordpress post?

I just upload 250x250 resolution images for all of my post. When i set one of the image as featured its getting cropped into 250x198.
I just want to use the uploaded image itself without any modification. I have tried Thumbnail Re-builder plugin,even it doesn't help me out.. :(
You need to set the post thumbnail dimensions:
http://codex.wordpress.org/Function_Reference/set_post_thumbnail_size
In your theme's functions.php file, add this line:
set_post_thumbnail_size( 250, 250, true );
You will need to rebuild your thumbnails after doing this. Ajax thumbnail rebuild is a great plugin for that.
See the codex link for more explanation.

Disable aspect ratio or image crop on wordpress custom header images

Can anyone help me with either disabling the aspect ratio for custom header image cropping in the wordpress 2011 theme, or disabling the cropping altogether?
At this stage I just need to get it done, even if it means modifying the core files. I've googled solutions, but have found none so far.
Thank you!
If I understand well what you want to do, I think you can look at the functions.php file of the theme.
You will see these lines :
// The height and width of your custom header.
// Add a filter to twentyeleven_header_image_width and twentyeleven_header_image_height to change these values.
define( 'HEADER_IMAGE_WIDTH', apply_filters( 'twentyeleven_header_image_width', 1000 ) );
define( 'HEADER_IMAGE_HEIGHT', apply_filters( 'twentyeleven_header_image_height', 288 ) );
// We'll be using post thumbnails for custom header images on posts and pages.
// We want them to be the size of the header image that we just defined
// Larger images will be auto-cropped to fit, smaller ones will be ignored. See header.php.
set_post_thumbnail_size( HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT, true );
// Add Twenty Eleven's custom image sizes
add_image_size( 'large-feature', HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT, true ); // Used for large feature (header) images
add_image_size( 'small-feature', 500, 300 ); // Used for featured posts if a large-feature doesn't exist
If you want to change the behaviour of the crop, you just have to set the third parameter of the *add_image_size()* function to false as you can see it in the add_image_size() codex page
I hope that's what you want, if not, let me know ;)

wordpress add thumbnail to post Excerpts plugin or method

I am looking for a way to add thumbnail images to post Excerpts.
I've installed: SuperSlider-Excerpt and Thumbnail For Excerpts plugins but I need to specifically assign the thumbnail that I want to use per post or automatically get the featured image to display as the thumbnail.
Anyone know a method or plugin that can do this please?
You can do this pretty easily with Wordpress. Like Francy said, the_post_thumbnail() will add the featured image you have picked on the post edit page in the admin section.
First you need to set up your thumbnails in your functions.php file. This is in the root directory of your theme (wp-content/themes/your-theme). Write this:
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 200, 200, false ); // Set your size, and clipping options
This would make thumbnails 200x200. You may want something else, so put whatever number you want in there.
Now that thumbnails are active, you can use the the_post_thumbnail() throughout your site, inside the loop, to display the thumbnail you've picked.
For example, if you want them to appear on the index page, head to index.php in your theme root directory, and write , right before . Experiment with where these appear, and get it in the right place for you.
Try within the loop:
the_post_thumbnail("thumbnail");
Or what also helped me was:
<?php
$image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'thumbnail');
$theImageSource = $image[0];
?>

Categories