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.
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.
With you alls help I was able to the desire thumbnail on the main page and product category pages. I followed Appearance > Customize > WooCommerce > Product Image.
However, on the individual product page, those actions don't apply. I am still getting cropped images. Any help with suggestions/advice would be appreciated.[enter
Try to add this in your child theme’s functions.php
add_filter( 'woocommerce_get_image_size_gallery_thumbnail', function( $size ) {
return array(
'width' => 150,
'height' => 150,
'crop' => 0,
);
});
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/
Basically, I'm trying to do a simple shortcode wherein the user can display a fixed size of an image regardless of the size. For Example [gallery] image [/gallery] it will be displayed like this
http://i255.photobucket.com/albums/hh140/testament1234/thumb_zps5820cef3.png
I tried coming up with my own code but looks like my codes are wrong. I'm not familiar with PHP or WordPress coding yet. I know things like this can be done using plugins but I would rather learn how to code
function image_gallery($atts, $content=null) {
extract(shortcode_atts(array(
'width' => 400,
'height' => 200,
), $atts));
return '<div class="gallery"></div>';
}
add_shortcode('gall', 'image_gallery' );
the styles was provided via style.css
function image_gallery($atts, $content=null) {
extract(shortcode_atts(array(
'width' => 400,
'height' => 200,
'image' => ''
), $atts));
return '<div class="gallery"><img src="'.$image.'" width="'.$width.'" height="'.$height.'" /></div>';
}
add_shortcode('gall', 'image_gallery' );
activate the plugin
in your post or page add this shortcode [gall image="path_to_your_image"]
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