Setting thumbnail featured image size not working properly - wordpress

Hi I just started today on creating my first Wordpress Theme and I am trying to create a featured Image for each post.Aldo I have managed to acomplish that it seems that the sizes I am giving it are not taking effect.Here is my code:
if(function_exists('add_theme_support')){
add_theme_support('post-thumbnails' , array('post'));
set_post_thumbnail_size(200,120);
}
if(function_exists('has_post_thumbnail') && has_post_thumbnail()){
the_post_thumbnail();
}
It seems that my featured images are not always set to the same size.For example if the image is smaller then what size I set it will remain the same , for big images the width is the same but for some the height is different.
What am I doing wrong here?

Are you setting the thumbnail size in functions.php? It will not work properly if it's just in index.php or another theme file.
From the codex:
This feature must be called before the init hook is fired. That means
it needs to be placed directly into functions.php or within a function
attached to the 'after_setup_theme' hook. For custom post types, you
can also add post thumbnails using the register_post_type function as
well.
the_post_thumbnail() displays the thumbnail and should be placed where you want the thumbnail to display.

Related

How stop wordpress creating thumbnails?

How can I stop Wordpress from making thumbnails? It uses a lot of my nodes, and memory!
How can I do this?
PS: My Wordpress site creates 3 images per uploaded image. (and I have galleies of 20-30 images per article => sooooooooo much nodes and memory)...
It's very simple to do this...
You have no visible option "stop Wordpress making thumbnails".
You must do the following:
Go to Settings -> Media
Uncheck "Crop thumbnail to exact dimensions (normally thumbnails are proportional)" if is checked
Set at Thumbnail size, Medium size and Large size the Width and Height to 0
Now Wordpress won't create you thumbnails.
I hope this will help you!
In wordpress when you upload new image that wordpress set it's thumbnail images accoring to set from admin panel or define in theme functions file.
Here is simple way for stop generating thumbnails by simple put below code in your theme function file.
function chnage_filter_image_sizes($sizes){
$sizes = array();
return $sizes;
}
add_filter('intermediate_image_sizes_advanced', 'chnage_filter_image_sizes');
Here if you want to generate own thumbnails with custome width and height whenever upload any image than just put parametes as below.
function chnage_filter_image_sizes($sizes){
$sizes = array('thumbnail_name'=>array('width'=>'120','height'=>'120','crop'=>true));
return $sizes;
}
add_filter('intermediate_image_sizes_advanced', 'chnage_filter_image_sizes')

Post thumbnails won't change size

I'm listing a lot of products on one page, and untill recently I used dimensions 390px*238px. Now I have to change the dimesions to something else, I updated get_the_post_thumbnail method with new parameters, page reloads and shows everything like I wanted it to be.
But, on next refresh, everything goes back as it were. When I inspect the elements, image that is displayed indeed has class attachment-390x501, but it's width, height and src attributes show 390, 238 and path/to/website/uploads/2012/11/Profile_IS_20180-390x238.jpg.
Is there a way to change my thumbnail dimensions? Here's the code I use currently:
<?php
// previous dimensions were 390x238
echo get_the_post_thumbnail($product->ID, array(390,501));
?>
You can set the size of the thumbnails by adding a line to your functions.php file and then display the new image size.
Add this to functions.php, you can change the numbers if you need to as that is the dimensions. Also, you can repeat this line as many times as you'd like to set different size thumbnails, just change new_custom_size to a unique name for each new size.
add_image_size( 'new_custom_size', 390, 501, true );
Then display your featured image with this:
<?php the_post_thumbnail('new_custom_size'); ?>
You will need to regenerate your thumbnails once you set the size in the functions.php file and before you display it on the page/post. I highly recommend the Renegerate Thumbnails plugin for this: http://wordpress.org/extend/plugins/regenerate-thumbnails/
use add_image_size and rebuild thumbnails

Different thumbnails sizes for different custom post types, and creating thumbnails for featured images only

I've got a wordpress site with a few custom post types. Each custom post type shows a list page, basically displaying a featured image and a title, and then you can click through to a detail page with a bunch more images.
I only need to resize uploaded "feature images". If an uploaded image isn't used as a feature image, I don't need a thumbnail for it. Furthermore, each custom post type shows a different sized feature image.
So, what I want to do is say:
a) Only create thumbnails for feature images
b) Create certain sizes for certain post types, and not for others.
Is this possible? At the moment, EVERY uploaded image is getting 5 thumbnail sizes, and my wp-content directory is WAAAY bigger than it needs to be!
Thanks in advance.
Ok I found a solution using the intermediate_image_sizes filter hook. Place this code in your functions.php and replace the 'post_type' and 'img_size_name' with the names of your post and desired image size.
add_filter( 'intermediate_image_sizes', function($sizes){
$type = get_post_type($_REQUEST['post_id']);
foreach($sizes as $key => $value){
if($type=='post_type' && $value != 'img_size_name'){
unset($sizes[$key]);
}
}
return $sizes;
});
To avoid waste of space, the best solution is to use phpthumb (http://phpthumb.sourceforge.net/) inside your page templates.

How to change default post attributes?

My site needs to have image based posts, meaning the post is only an image.
Now i tried implementing it with Custom Post Types, but have encoutred problems,
like categories didn't show the right posts, pagination caused problems etc.
Now i thought to myself that i don't need the regular posts and if i could just edit them
to have only the featured image option enabled, life would be much easier.
But i failed to find any information regarding this.
Anyone can help me please?
To add featured image support/option simply add the following code snippet to your functions.php file located inside your theme's root folder
if ( function_exists( 'add_theme_support' ) ) {
add_theme_support( 'post-thumbnails' );
}
and to show the featured image inside your template you can do
if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
the_post_thumbnail(); // will show the featured image if you have set any for the post
}
Applicable to Wordpress version-2.9 and higher.
When you add new post just find the featured image meta box and set an featured image from there.
You can also setup image sizes (depending on that images will be displayed) at the front end, just take a look at here.

Youtube dimensions wordpress

Is it possible to change the default embed dimensions of an youtube (or another video) in Wordpress for your current theme? I've searched for a plugin and some code, but I can't seem to find any.
What I mean is the default embed size used when you just paste an youtube url in an post or page.
Open your theme’s functions.php file, and add the following code:
if ( ! isset( $content_width ) ) $content_width = 600;
Remember to change the number 600 appropriately for your theme. It is the maximum width in pixels for your content area.
Once you do this, WordPress will automatically use that for the maximum width of your oEmbed elements (youtube videos, slideshare, etc).
via wpbeginner.com
The media settings have been removed. You can do it with a filter however.
function mycustom_embed_defaults($embed_size){
$embed_size['width'] = 600; // Adjust values to your needs
$embed_size['height'] = 500;
return $embed_size; // Return new size
}
add_filter('embed_defaults', 'mycustom_embed_defaults');
Taken from here http://shailan.com/2154/change-wordpress-default-embed-size-using-filters/
The currently accepted answer has an example that uses the following shortcode:
[youtube=http://www.youtube.com/watch?v=0Bmhjf0rKe8&w=640&h=385]
The shortcode [youtube] only works if you have the Jetpack plugin installed.
To make it work with WordPress with no Jetpack you can use the built-in [embed] shortcode like this:
[embed width=640 height=385]http://www.youtube.com/watch?v=0Bmhjf0rKe8[/embed]
To change the default embed size go to Settings > Media and just set a fixed width/height.
You also have the shortcode
[youtube=http://www.youtube.com/watch?v=0Bmhjf0rKe8&w=640&h=385]
where you can manually insert width and height as params. This shortcode will overwrite the default WP settings.
They've got rid of the fixed width/height option in the media settings of the new version of Wordpress. Not sure why. It was useful!! Shortcodes don't seem to work either.

Resources