While developing wordpress theme, you wont get section to add post image. So you need to add the following codes to function.php
To display thumbnail in single.php or page.php (anywhere in frontend), you need to insert this code inside php
// Add feaure image thumbnail function thumbnail_add(){ add_theme_support( 'post-thumbnails' ); } add_action("after_setup_theme","thumbnail_add");
add_action is an action hook we use “after_setup_theme” as action hook, and thumbnai_add is function name above
You can use the following code in function.php for different pages
the_post_thumbnail();
add_theme_support( 'post-thumbnails' );
2. ONLY PAGES
add_theme_support( 'post-thumbnails', array( 'page' ) );
3. ONLY POSTS
add_theme_support( 'post-thumbnails', array( 'post' ) );
O3. NLY CUSTOM POST TYPES
add_theme_support( 'post-thumbnails', array( 'your-post-type-name' ) );
The example of array are as follow which might be the possible arrays
array(
'height'=>50,
'width'=>200,
'default-image' => '',
'default-preset' => 'default', // 'default', 'fill', 'fit', 'repeat', 'custom'
'default-position-x' => 'left', // 'left', 'center', 'right'
'default-position-y' => 'top', // 'top', 'center', 'bottom'
'default-size' => 'auto', // 'auto', 'contain', 'cover'
'default-repeat' => 'repeat', // 'repeat-x', 'repeat-y', 'repeat', 'no-repeat'
'default-attachment' => 'scroll', // 'scroll', 'fixed'
'default-color' => '',
'wp-head-callback' => '_custom_background_cb',
'admin-head-callback' => '',
'admin-preview-callback' => '',
);
CUSTOM LOGO
You can also customize your thumbails that is small size or banner size. you can use the following code in function.php
add_image_size('small-thumbnail',12,90,true);
where 120 is width , 90 is height, true gives cropping value true whereas false denote no cropping. ‘small-tumbnail’ is name of the thumbnail you can use while calling.
in your page (index.php,single.php,page.php…) you can call the custom thumbnail by using this code
the_post_thumbnail('small-thumbnail');
After 20 years of transforming global communication, Skype has officially ceased operations. Microsoft, which purchased…
In a serene forest by the edge of a sparkling lake, there lived a cheerful…
Retiring comfortably is a goal many aspire to achieve, and with the right strategies, it’s…
Is your computer running frustratingly slow? Don't worry; you're not alone in facing this common…
Once, in a sunny forest, Fox and Crow were friends. One day, Crow found a…