I created a wordpress theme based on the classic twentyten theme.
I changed the size of the header images in the functions.php but apart from that I didnt mess around with the custom header stuff. Now wordpress is ignoring it when I assign featured images to pages and instead only displays the background selected in the header settings.
The size of the image doesnt seem to have anything to do with the problem. I have tried using the exact image size and larger images, they are always ignored...
Thanks if you can help!
PS. Here a link to the website: http://stuck-mueller.de/beta/
here is the code from the functions.php:
// The custom header business starts here.
$custom_header_support = array(
// The default image to use.
// The %s is a placeholder for the theme template directory URI.
'default-image' => '%s/images/headers/path.jpg',
// The height and width of our custom header.
'width' => apply_filters( 'twentyten_header_image_width', 960 ),
'height' => apply_filters( 'twentyten_header_image_height', 240 ),
// Support flexible heights.
'flex-height' => true,
// Don't support text inside the header image.
'header-text' => false,
// Callback for styling the header preview in the admin.
'admin-head-callback' => 'twentyten_admin_header_style',
);
add_theme_support( 'custom-header', $custom_header_support );
if ( ! function_exists( 'get_custom_header' ) ) {
// This is all for compatibility with versions of WordPress prior to 3.4.
define( 'HEADER_TEXTCOLOR', '' );
define( 'NO_HEADER_TEXT', true );
define( 'HEADER_IMAGE', $custom_header_support['default-image'] );
define( 'HEADER_IMAGE_WIDTH', $custom_header_support['width'] );
define( 'HEADER_IMAGE_HEIGHT', $custom_header_support['height'] );
add_custom_image_header( '', $custom_header_support['admin-head-callback'] );
add_custom_background();
}
// We'll be using post thumbnails for custom header images on posts and pages.
// We want them to be 940 pixels wide by 198 pixels tall.
// Larger images will be auto-cropped to fit, smaller ones will be ignored. See header.php.
set_post_thumbnail_size( $custom_header_support['width'], $custom_header_support['height'], true );
You don't need the apply_filters() just assign the width and height to integers like:
'width' => 960,
'height' => 240,
Check out the codex here for more info
Related
I'm using woocommerce hooks with thumbnail regenerate plugin but still have same issue i didn't see any changes in my website i removed cache as well.
add_filter( 'woocommerce_get_image_size_gallery_thumbnail', 'override_woocommerce_image_size_gallery_thumbnail');
function override_woocommerce_image_size_gallery_thumbnail( $size ) {
// Gallery thumbnails: proportional, max width 200px
return array(
'width' => 100,
'height' => 100,
'crop' => 0,
);
}
I think the answer to that is in the "Appearance / Customize" then Woocommerce. There you can choose how products images are cropped.
How can I make the user change any image on my wp theme just from the theme editor?
For example: I have a background image on my theme footer that i hard-coded, I want to give the user(admin) the ability to change it from the theme editor, and thanks on advanced
I don't want to use something like this:
<div class="footer-background background-image" style="background-image: url(<?php echo get_theme_file_uri( 'assets/images/bg.jpg' ) ?>)" >
If you can just give me a wp codex on this, it would be more than helpful, because I couldn't find any thing related to my problem on Google.
So, you could do something like that (in functions.php) :
add_action( 'customize_register', function( $wp_customize ) {
$wp_customize->add_section(
'section_img',
array(
'title' => 'Images',
'priority' => 35,
)
);
$wp_customize->add_setting(
'footer_image'
);
$wp_customize->add_control(
new WP_Customize_Image_Control(
$wp_customize,
'footer_image',
array(
'label' => 'Footer image',
'section' => 'section_img',
'settings' => 'footer_image'
)
)
);
});
And you get the value by doing (in footer.php) :
get_theme_mod('footer_image');
If I were you, I do followings
Install ACF plugin
Create an option Page
Create new custom field (image field) and assign it to previously created options page.
Update footer template to show the image from back end like this
Update footer image src to get back end ACF field value.
https://www.advancedcustomfields.com/resources/options-page/
https://www.advancedcustomfields.com/resources/image/
using WooCommerce I put this snippet in function.php to define the size of images overwriting the panel settings :
function yourtheme_woocommerce_image_dimensions() {
$single = array(
'width' => '400', // px
'height' => '300', // px
'crop' => 1 // true
);
$thumbnail = array(
'width' => '180', // px
'height' => '135', // px
'crop' => 1 // false
);
$catalog = array(
'width' => '140', // px
'height' => '105', // px
'crop' => 1 // true
);
// Image sizes
update_option( 'shop_single_image_size', $single ); // Single product image
update_option( 'shop_thumbnail_image_size', $thumbnail );
update_option( 'shop_catalog_image_size', $catalog ); // Product category thumbs
All works fine but now I'd like to set different image sizes relating to $catalog just in single product page (where there's a widget showing that images).
I've tried with conditional statements, cause I don't want to use css tricks, but without luck.
Any help will be appreciate.
Thank you.
Did you re-generate the thumbnails after changing the size? If no, than try force regenerate thumbnails plugin to re-generate images that will have new sizes. When indicating new size in Wp functions, than it will affect new uploads but you also need to regenerate new sizes for previously uploaded ones.
Setting the size for a thumbnail is not a problem, but I also want to crop the image from top and to the left, but it's not working!
Inside functions.php I have this code:
function theme_setup() {
register_nav_menus(array(
'primary' => __('Main Menu'),
'footer' => __('Footer Menu'),
));
add_theme_support('post-thumbnails');
add_image_size('thumbnail', 300, 300, true);
add_image_size('post', 800,400, true);
}
add_action('after_setup_theme', 'theme_setup');
I have tested to add this code inside the function:
add_image_size('thumbnail', 300, 300, array( 'top', 'left'));
But it's not cropping from top left. All thumbnails are cropped center center
I saw this code on the WordPress Codex page:
set_post_thumbnail_size( 300, 300, array( 'top', 'left') );
If I should use this insted, how should I add this in functions.php to get it to work? I just tested to paste it in the code, but it's not working that either!
Any ideas why my code isn't working or suggestion how to improve the code?
EDIT: I forgot to write that I also has used the plugin Regenerate Thumbnails before I have changed the settings for the thumbnails.
Wordpress Question:
In the "Header Image" section of my Wordpress dashboard, it indicates, "Images of exactly 1280 × 416 pixels will be used as-is." But when I upload an image of that size, the image is cropped at the top and bottom (I'm using the Hemingway theme). Plus, when I do an "Inspect Element" on the header image, it indicates the image is only 1214 x 243 pixels. Yet there appears to be no cropping in the x-direction. Both of these are unexpected considering the Wordpress instructions on the header page. Can someone shed some light on this?
Thanks in advance.
edit: fwiw my site is www.panyadee.ac.th/test/
Take a look in your theme's functions.php file for add_theme_support. This function registers support for the custom header image. Regarding the width and height of the default image, you can pass some $args like this:
$default_args = array(
'default-image' => '',
'random-default' => false,
'width' => 0,
'height' => 0,
'flex-height' => false,
'flex-width' => false,
'default-text-color' => '',
'header-text' => true,
'uploads' => true,
'wp-head-callback' => '',
'admin-head-callback' => '',
'admin-preview-callback' => '',
);
add_theme_support( 'custom-header', $default_args );
Try making sure that height and width are set.
Ref: http://codex.wordpress.org/Function_Reference/add_theme_support
Wordpress cuts some area to provide an option to crop the uploaded image. You need to extend the bottom area from the cropping region according to your mentioned size.