I have an website where you can upload from front end and when you make a new post the image goes into custom field imagepost and Wordpress makes 3 more images after the original with diferent sizes and dimension and if I make to set automatically original image as thumbnail some images are bigger than 8 mb and facebook says can't download my image so I need a solution to get into thumbnail image generated by wordpress , ex: image-300.270.jpg not the original image.
You can add new sizes of images with:
add_image_size( $name, $width, $height, $crop );
You have to do this in your functions.php archive.
If I am correct all you need to do is to call the actual image for your post thumbnail with a function the_post_thumbnail( $size, $attr );
According to this page you can call multiple default post thumbnail sizes like this:
the_post_thumbnail(); // without parameter -> 'post-thumbnail'
the_post_thumbnail( 'thumbnail' ); // Thumbnail (default 150px x 150px max)
the_post_thumbnail( 'medium' ); // Medium resolution (default 300px x 300px max)
the_post_thumbnail( 'large' ); // Large resolution (default 640px x 640px max)
the_post_thumbnail( 'full' ); // Full resolution (original size uploaded)
the_post_thumbnail( array(100, 100) ); // Other resolutions
More info here : https://developer.wordpress.org/reference/functions/the_post_thumbnail/
Related
this is my php code and i want to add the size thumbnail max 300x420
<a class="blog-views" href="<?php the_permalink(); ?>"><?php
the_post_thumbnail('full'); ?></a>
i have get from wordpress this code, but this do not help me, thumbnail, medium, mdeium large, large and full.
the_post_thumbnail( 'thumbnail' ); // Thumbnail (150 x 150 hard cropped)
the_post_thumbnail( 'medium' ); // Medium resolution (300 x 300 max height 300px)
the_post_thumbnail( 'medium_large' ); // Medium Large (added in WP 4.4) resolution (768 x 0 infinite height)
the_post_thumbnail( 'large' ); // Large resolution (1024 x 1024 max height 1024px)
the_post_thumbnail( 'full' ); // Full resolution (original size uploaded)
Try to use this code:
the_post_thumbnail( array(300,420) );
You can use set_post_thumbnail_size( 300, 420, true );
For more information follow this link set_post_thumbnail_size
You can change thumbnail size from admin side, wp-admin/options-media.php
I found a plugin called oEmbed Featured Image that does absolutely everything I want except output the largest size.
The plugin's default YouTube output size is 480x360. I need to be able to use the full resolution size for at least YouTube/Vimeo.
I figured I can edit the function starting on line 68 in the plugin.
Here is what I've come up with:
public function oembed_dataparse( $return, $data, $url )
{
if ($yt = $data->provider_name == 'YouTube')
{
if(preg_match("/^(?:http(?:s)?:\/\/)?(?:www\.)?(?:m\.)?(?:youtu\.be\/|youtube\.com\/(?:(?:watch)?\?(?:.*&)?v(?:i)?=|(?:embed|v|vi|user)\/))([^\?&\"'>]+)/", $data->thumbnail_url, $youtube_id))
$ytvideo_id = $youtube_id;
$max = get_headers($data->thumbnail_url);
if (substr($max[0], 9, 3) !== '404')
{
$data->thumbnail_url = 'http://img.youtube.com/vi/$ytvideo_id/maxresdefault.jpg';
}
}
if ($vm = $data->provider_name == 'Vimeo')
{
if (preg_match("/https?:\/\/(?:www\.)?vimeo.com\/(?:channels\/(?:\w+\/)?|groups\/([^\/]*)\/videos\/|album\/(\d+)\/video\/|)(\d+)(?:$|\/|\?)/", $data->thumbnail_url, $vimeo_id))
$vmvideo_id = $vimeo_id[3];
$hash = unserialize(file_get_contents("http://vimeo.com/api/v2/video/$vmvideo_id.php"));
$data->thumbnail_url = $hash[0]['thumbnail_large'];
}
if ( ! empty( $data->thumbnail_url ) && ! $this->_thumb_id ) {
//if ( in_array( # $data->type, array( 'video' ) ) ) // Only set for video embeds
$this->set_thumb_by_url( $data->thumbnail_url, # $data->title );
}
}
In this link there are the explanation how you can change the preset of wp.
Featured Images & Post Thumbnails
I think you could found interesting, probably you don't need use plug-in. the_post_thumbnail( 'full' ); // Original image resolution (unmodified)
In the link it's write:
The default image sizes of WordPress are “Thumbnail”, “Medium”, “Large” and “Full Size” (the original size of the image you uploaded). These image sizes can be configured in the WordPress Administration Media panel under >Settings > Media. You can also define your own image size by passing an array with your image dimensions:
he_post_thumbnail(); // Without parameter ->; Thumbnail
the_post_thumbnail( 'thumbnail' ); // Thumbnail (default 150px x 150px max)
the_post_thumbnail( 'medium' ); // Medium resolution (default 300px x 300px max)
the_post_thumbnail( 'large' ); // Large resolution (default 640px x 640px max)
the_post_thumbnail( 'full' ); // Original image resolution (unmodified)
the_post_thumbnail( array( 100, 100 ) ); // Other resolutions (height, width)
Set the Featured Image Output Size #Set the Featured Image Output Size
To be used in the current Theme’s functions.php file.
You can use set_post_thumbnail_size() to set the default Featured Image size by resizing the image proportionally (that is, without distorting it):
set_post_thumbnail_size( 50, 50 ); // 50 pixels wide by 50 pixels tall, resize mode
Set the default Featured Image size by cropping the image (either from the sides, or from the top and bottom):
set_post_thumbnail_size( 50, 50, true ); // 50 pixels wide by 50 pixels tall, crop mode
In this link you can see more code: https://developer.wordpress.org/reference/functions/the_post_thumbnail/
When using the_post_thumbnail() or related functions, the ‘post-thumbnail’ image size is used by default, though a different size can be specified instead as needed.
Other link i think you can found interesting is this: Image Size and Quality
But it's more generic.
The video work in the some way. of course depends from quality of the video in youtube and you can decide how large you want show up. If you don't use a differente media player, you will use a default youtube player and you can use the API for do what you want.
I hope I was helpful.
What you need to do is actually modify you youtube if statement to make it look at $url, not $data->thumbnail_url. That will cause your preg_match() to match correctly, and it will return the correct $yt_videoid for you to use.
I'am trying to make custom thumbnail sizes in Wordpress. Currently I have following code in functions.php
<?php
add_image_size( 'featuredImageCropped', 310, 150, false );
function custom_excerpt_length( $length ) {
return 15;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
And I'am trying to access this thumbnail in index.php with following code:
<img class="keis-image" src="<?php $kuva = get_field('kuva');$image = wp_get_attachment_image_src( $kuva['id'], "featuredImageCropped"); echo $image[0] ?>"/>
However it will return full image instead of resized thumbnail, if I change featuredImageCropped to large or some other basic thumbnail size it will return it as it should.
How could I get my custom thumbnail to render as I'd like to?
According to add_image_size() in the Documentation:
Add this to your theme's functions.php :
add_action( 'after_setup_theme', 'mytheme_custom_thumbnail_size' );
function mytheme_custom_thumbnail_size(){
add_image_size( 'thumb-small', 200, 200, true ); // Hard crop to exact dimensions (crops sides or top and bottom)
add_image_size( 'thumb-medium', 520, 9999 ); // Crop to 520px width, unlimited height
add_image_size( 'thumb-large', 720, 340 ); // Soft proprtional crop to max 720px width, max 340px height
}
To display a featured image with your new size (in this case “thumb-small”) in a post, just add:
<?php if ( has_post_thumbnail() ) { the_post_thumbnail( 'thumb-small' ); } ?>
If your theme does not support featured images, you need to add this to your functions.php as well, inside of your setup function.
// Enable featured image
add_theme_support( 'post-thumbnails' );
If you add new thumbnail sizes to a site which already has media uploaded, you’ll need to regenerate thumbnails once for the new sizes to show up using this plugin:
Regenerate Thumbnails
Thumbnail Sizes
The default image sizes of WordPress are “thumbnail”, “medium”, “large” and “full” (the size of the image you uploaded). These image sizes can be configured in the WordPress Administration Media panel under Settings > Media. This is how you can use these default sizes with the_post_thumbnail():
the_post_thumbnail(); // without parameter -> 'post-thumbnail'
the_post_thumbnail( 'thumbnail' ); // Thumbnail (default 150px x 150px max)
the_post_thumbnail( 'medium' ); // Medium resolution (default 300px x 300px max)
the_post_thumbnail( 'large' ); // Large resolution (default 640px x 640px max)
the_post_thumbnail( 'full' ); // Full resolution (original size uploaded)
the_post_thumbnail( array(100, 100) ); // Other resolutions
I have this code to show the featured images of my wordpress posts on mailchimp RSS Campaigns and it works but it shows the image on its original size, I was wondering if you could help me with the code in order to resize all images to a same size.
function featuredtoRSS($content) {
global $post;
if ( has_post_thumbnail( $post->ID ) )
{
$content = '' . get_the_post_thumbnail( $post->ID, 'full', array( 'style' => 'float:left; margin:10px 15px px 0;' ) ) . '' . $content;
}
return $content;
}
This is a wordpress question, but here is the answer
YOu should make an your own image size and add it in wordpress functions.php
add_image_size( 'samesize', 500, 200, true );
You can read more about it here
And then in your code you will call your image size instead of full (full means the full width and height copy of your image)
get_the_post_thumbnail( $post->ID, 'samesize'
rest of your code :)
Your current styles are not going to resize your image. float:left; will push your image to the left, and margin will simply add spacing on each side of the image.
You are looking for width: ; and height: ;.
Checkout post_thumbnail function ref. that's what you're looking for,
on most templates there are already some default sizes:
the_post_thumbnail(); // without parameter -> 'post-thumbnail'
the_post_thumbnail( 'thumbnail' ); // Thumbnail (default 150px x 150px max)
the_post_thumbnail( 'medium' ); // Medium resolution (default 300px x 300px max)
the_post_thumbnail( 'large' ); // Large resolution (default 640px x 640px max)
the_post_thumbnail( 'full' ); // Full resolution (original size uploaded)
plus with an array you can set
the_post_thumbnail( array(100, 100) ); // Other resolutions
This works inside the loop, to access the function from outside use the get_the_post_thumbnail()
to set new sizes use add_image_size().
I'am trying to make custom thumbnail sizes in Wordpress. Currently I have following code in functions.php
<?php
add_image_size( 'featuredImageCropped', 310, 150, false );
function custom_excerpt_length( $length ) {
return 15;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
And I'am trying to access this thumbnail in index.php with following code:
<img class="keis-image" src="<?php $kuva = get_field('kuva');$image = wp_get_attachment_image_src( $kuva['id'], "featuredImageCropped"); echo $image[0] ?>"/>
However it will return full image instead of resized thumbnail, if I change featuredImageCropped to large or some other basic thumbnail size it will return it as it should.
How could I get my custom thumbnail to render as I'd like to?
According to add_image_size() in the Documentation:
Add this to your theme's functions.php :
add_action( 'after_setup_theme', 'mytheme_custom_thumbnail_size' );
function mytheme_custom_thumbnail_size(){
add_image_size( 'thumb-small', 200, 200, true ); // Hard crop to exact dimensions (crops sides or top and bottom)
add_image_size( 'thumb-medium', 520, 9999 ); // Crop to 520px width, unlimited height
add_image_size( 'thumb-large', 720, 340 ); // Soft proprtional crop to max 720px width, max 340px height
}
To display a featured image with your new size (in this case “thumb-small”) in a post, just add:
<?php if ( has_post_thumbnail() ) { the_post_thumbnail( 'thumb-small' ); } ?>
If your theme does not support featured images, you need to add this to your functions.php as well, inside of your setup function.
// Enable featured image
add_theme_support( 'post-thumbnails' );
If you add new thumbnail sizes to a site which already has media uploaded, you’ll need to regenerate thumbnails once for the new sizes to show up using this plugin:
Regenerate Thumbnails
Thumbnail Sizes
The default image sizes of WordPress are “thumbnail”, “medium”, “large” and “full” (the size of the image you uploaded). These image sizes can be configured in the WordPress Administration Media panel under Settings > Media. This is how you can use these default sizes with the_post_thumbnail():
the_post_thumbnail(); // without parameter -> 'post-thumbnail'
the_post_thumbnail( 'thumbnail' ); // Thumbnail (default 150px x 150px max)
the_post_thumbnail( 'medium' ); // Medium resolution (default 300px x 300px max)
the_post_thumbnail( 'large' ); // Large resolution (default 640px x 640px max)
the_post_thumbnail( 'full' ); // Full resolution (original size uploaded)
the_post_thumbnail( array(100, 100) ); // Other resolutions