I have a little problem... when I want to show the featured image on my posts, the chosen size isn't working (the photo is shown in it's own size). And I want the featured Image to be shown in the same width as the post total width but I have no clue!
This is the code I'm using in the PHP section
if ( function_exists( 'add_theme_support' ) ) add_theme_support( 'post-thumbnails' ); set_post_thumbnail_size(640, 205);
My question is... where do I have to put this code?
<?php add_theme_support( 'post-thumbnails' );?>
And what would be the css I have to use to show it in the same width as the post total width?
Thanks
Put the php code add_theme_support( 'post-thumbnails' ); on functions.php under the theme directory.
WordPress cutting thumbnails while uploading the file, so you have to enable the feature first then upload the image.
Put this code add_theme_support( 'post-thumbnails' ); in function.php file
Select Post option,at right side bar corner,you will find the option as Featured images changes and updates,select and update the image which you require.
Else try with this Code format:
the_post_thumbnail();
set_post_thumbnail_size( 50, 50);`add_image_size( 'single-post-thumbnail', 590, 180 );
Related
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/
I would like to have the first product gallery image on the background of the single product page (Woocommerce).
I know how do it with CSS to set background-img URL but im not a php developer, so its to hard for me to fix it.
Untested! However, you could try this:
<body style="background-image: url('<?php echo get_the_post_thumbnail_url( get_the_ID(), 'large' ); ?>');">
If you have thumbnail image theme supports, large should be available. If not, add add_theme_support( 'post-thumbnails' ); to your functions.php file first.
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
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.
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];
?>