May 2014 update: Now added in the core code of Customizr since v3.1.11
When the sliders are displayed in full width, you might encounter some frustrating cropping effect for your slides, especially on very large screen devices.
This snippet automatically keeps the slides vertically centered on any devices.
add_action ('wp_footer','tc_slider_adjust' ); function tc_slider_adjust() { global $wp_query; $queried_id = get_queried_object_id(); $queried_id = ( !tc__f('__is_home') && $wp_query -> is_posts_page && !empty($queried_id) ) ? $queried_id : get_the_ID(); $slider_active = esc_attr(get_post_meta( $queried_id, $key = 'post_slider_check_key' , $single = true )); if ( tc__f('__is_home') && tc__f('__get_option','tc_front_slider') !=null) { $slider_active = true; } if(!$slider_active) { return; } ?> <script type='text/javascript'> jQuery(document).ready(function() { !function ( $) { //prevents js conflicts "use strict"; function setposition( item , HeightSliderContainer ) { var Img = item.find('img'), ImgSrc = Img.attr('src'), ImgHeight = Img.height(), Adjustment = Math.ceil(( ImgHeight - HeightSliderContainer )*0.5); if (Adjustment > 0) { Img.css('top', -Adjustment + 'px'); Img.css('position','relative'); } } function adjust( item ) { var HeightSliderContainer = $('.carousel-inner').height(); $('.item' , '.carousel-inner').each(function() { var has_active = $(this).hasClass('active'), ImgHeight = $(this).find('img').height(); $(this).addClass('active'); setposition($(this) , HeightSliderContainer); if (!has_active) { $(this).removeClass('active'); } }); } adjust(); $(window).resize(function () { adjust(); }); }(window.jQuery); }); </script> <?php }
Where to paste this code? => in your functions.php file. I strongly recommend to create a child theme. Download a start-up child theme here.
Everything you need to know about child theme with Customizr here.
18 thoughts on “Customizr slider : centering your slides vertically in full width mode”
Hi, thanks for the information but as it can be read above, is not working for wp 4.2.2. IIs there any solution available for this version? We would be so gratefull of receiveing it as the appearance of the slider in full width is much better.
Thank you again, i hope we get to fix this problem!
Hi Natale, thanks for getting in touch.
Would you mind reporting this issue in the support forum ?
Thanks 🙂
Hi Nicolas
A great theme my only gripe is the slider. I have read everything posted here and other places and there does not seem to be a simple solution. If the height is locked at 500px and width is 100%, what would cause the image to be cropped if the image is the same height?
Since i don’t like playing around with the code as you can do more damage than good as a i need a solution asap, so can disable the slider and insert another one
Hello Nikolas!
First of all; thanks for a great theme!
I have a problem with my sliders. In the settings I have chosen for full width. But when I look on my Mac computer, the right side of the screen isn’s covered totally. What is the adjustment in the css code I have to make?
Thnks in advance!
Marco
Hi,
You’ll want to replace
.carousel .item {
width: 1700px;
}
by
.carousel .item {
width:100%;
}
And you should be good to go!
Works like a charme Nicolas, thanks very much!
Where am I going to replace the lines of code you suggested? The scrolling banner seems to be viewing fine on most Macbooks and mobile devices. Seems to be cutting off the bottom on a few other machines. Not sure why this is. I played with the new built in settings. Nothing seems to work.
Replace
.carousel .item {
width: 1700px;
}
by
.carousel .item {
width:100%;
}
This code did not work and still the slide crops off at the bottom edge, though i don’t have full width set
Hi Sally, this code is now implemented in the core of the theme since v3.1.11. You can disable this in apperance > customizer > responsive settings.
Cheers
Hi Nicolas,
I’ve been trying to edit the sizing/cropping of the slider for quite a while now through a variety of methods on this site. Please forgive my ignorance on this issue, but if I create a functions.php file in my child directory, do I paste the above verbatim into it?
And, also, since I have tried that, had fatal errors, deleted it, tried making changes to the original functions file and the child CSS file, and I’ve gotten nowhere with being able to change the cropping of my images, I thought I would just ask if this would even fix my issue. The slider I am working on it located on the page http://www.omfairy.com/about-courtney-krishnamurthy/
No matter how small/large/different ratio’d I make my images, I seem to end up with the bottoms cut off. The ideal solution for me would be for the image to scale according to width still showing the full height (e.g. if the image is 800×600 and the window is 800 pixels wide, the image stays 800×600… if the window is 400, the image scales to 400×300). Is there any possible way to do this? If not, I’m thinking the centering is my next best option, as I can control the cropping of my images to have what I need to show centered.
Many thanks for any feedback! I love the theme, if I can just get the slider to work for me I’ll be ecstatic!
Hi Courtney, you did a nice website!
If you are new to Customizr (and WordPress), you might want to read this short guide on how to customize Customizr.
If you still have issues then post a new thread in the the Customizr user’s forum and we’ll do our best to help you.
Thanks and best regards
Thanks Nicolas! I have been through the guide, so I’ll start a new thread today. Appreciate the help!
… apologies, forgot to tick notification of followup comments, so just ticking it now.
Thanks for this feedback @Abby. I am working on a fix for this. It will be included in the next release of theme coming soon.
Stay tuned!
Best
Sometimes this code works but other times it doesn’t…. can’t figure out the reason… anyone else had this issue?
@Briony, yes this happens to me. Can’t work out the pattern, but I’m leaning towards saying the first time it loads after clearing cookies, it’s loading correctly. But then while working on the site, repeated loading seems to throw a spanner in the works… Not sure.
Nic, thank you so much for creating such a beautiful theme. Really enjoying working with it. Any help would be greatly appreciated.
You can see the adjusted slider here: http://relocationexcellence.com/wordpress/
My sliders are reduced to narrow stripes, and my clients are mostly using wide screen divises. it renders the Customizr completely usless for me. It is a pity as otherwise I love the theme.
I have tried to isert the code after creating a child theme, did not work. I have tried to use it with the Code Snippets plugin and it did not work neither.
Nicolas can you just insert this snipped in the theme code and it would update itself automatically?
Hi Mirek, I will probably add this as a checkbox in the next release of the theme.
Thanks for this feedback and enjoy the theme