Skip to content

Instantly share code, notes, and snippets.

@aliaghdam
Last active February 5, 2022 09:34
Show Gist options
  • Star 17 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
  • Save aliaghdam/414d6e7f916c056a121a98ba64d0b7c0 to your computer and use it in GitHub Desktop.
Save aliaghdam/414d6e7f916c056a121a98ba64d0b7c0 to your computer and use it in GitHub Desktop.
WordPress Visual Composer full width row ( stretche row ) fix for RTL
jQuery(document).ready(function() {
function bs_fix_vc_full_width_row(){
var $elements = jQuery('[data-vc-full-width="true"]');
jQuery.each($elements, function () {
var $el = jQuery(this);
$el.css('right', $el.css('left')).css('left', '');
});
}
// Fixes rows in RTL
jQuery(document).on('vc-full-width-row', function () {
bs_fix_vc_full_width_row();
});
// Run one time because it was not firing in Mac/Firefox and Windows/Edge some times
bs_fix_vc_full_width_row();
});
@smayar
Copy link

smayar commented Mar 12, 2017

Hello,
where i can use the above codes to fix the row issue in RTL?

@aliaghdam
Copy link
Author

aliaghdam commented Mar 30, 2017

Hi @samyar

You have to add that code into your theme.

don't forget to put it i inside <script></script> tag.

@shafi796
Copy link

While use this code not working Left to Right

@az-rad
Copy link

az-rad commented Jul 21, 2017

WOOOWWWWW
Thanks alot.... I was looking for answer for 2 weeks. Thanks mannnnnn. You can't imagine how much i am happy now. Thanks.
I hope the best for you !!!!!

@imatteh
Copy link

imatteh commented Aug 24, 2017

Thank's :)

@aliaghdam
Copy link
Author

@arsalanzr @imatteh awesome to know it helped you :)

@aliaghdam
Copy link
Author

@shafi796 You have to check your current active plugins. a plugin conflict can be the reason!

@az-rad
Copy link

az-rad commented Oct 5, 2017

Hi @aliaghdam
Thank u for your help. I don't what happened but lately The code is not working on safari any more (Chrome and firefox is ok still). I don't know what to do. I don't know it is because of Visual composer update 5.3 or it is because of safari. Do know any thing about this?
I would be grateful if you help me on this :(.

U can see the issue on this page: https://nicvo.com

Best Regards
Arsalan

@aliaghdam
Copy link
Author

@arsalanzr I checked your site and it works properly!!

@aliashjaei
Copy link

dadash damet garm harf nadari

@yanivalm
Copy link

Hi, can you please let me know which file in wordpress install should i add this code? If i use a child theme can i update the child theme?

@nrkhatana
Copy link

wonderful. thank you so much :)

@serguk89
Copy link

serguk89 commented Dec 20, 2017

[css]
body.rtl .vc_row[data-vc-full-width] {
position: relative;
left: 50%;
right: 50%;
margin-left: -50vw;
margin-right: -50vw;
width: 100%;
width: 100vw !important;
}

@toanphungduc
Copy link

Thank serguk89! Your solution worked with my project.

@mahbobeh1993
Copy link

How to use this code in my template?
Where do I put Js file?

@mahbobeh1993
Copy link

mahbobeh1993 commented Jan 12, 2018

@serguk89
I use your code in my theme but row is very strech .
help me.

@johnnysurf
Copy link

Worked perfectly! Thanks @aliaghdam!

@mawad008
Copy link

mawad008 commented Apr 3, 2018

thanks ;)

@WWGate
Copy link

WWGate commented May 17, 2018

CSS Solution:

body.rtl .vc_row[data-vc-full-width] {
	position: relative;
	width: 100vw !important;
    right: 50% !important;
    left: auto !important;
    transform: translateX(50%) !important;
    padding-left: calc( (100vw - 1140px) / 2 ) !important;
    padding-right: calc( (100vw - 1140px) / 2 ) !important;
}
@media(max-width:767px){
	body.rtl .vc_row[data-vc-full-width] {
	    padding-left: 15px !important;
	    padding-right: 15px !important;
	    margin-right: 0 !important;
	    margin-left: 0 !important;
	}
}

I hope it help

@TakiDDine
Copy link

thank you so so so much , thank you !! thank you , you saved me <3 <3 <3

@ahmader
Copy link

ahmader commented Aug 16, 2018

Worked like a charm!

@isotopie
Copy link

@serguk89
Thanks

@arj-89
Copy link

arj-89 commented Dec 25, 2018

Well, thank you all so much. this helped me a lot 👍
but, I had to tweak it a little bit.

I did it as a separate class on each row needed a fix. and I used 2 classes.

.fixRtl { position: relative; left: 50%; right: 50%; margin-left: -50vw; margin-right: -50vw; width: 100%; width: 100vw !important; padding-left: calc( (100vw - 1140px) / 2 ) !important; padding-right: calc( (100vw - 1140px) / 2 ) !important; }

and the other one was:

.fixRtlTwo { position: relative; left: 50%; right: 50%; margin-left: -50vw; margin-right: -50vw; width: 100%; width: 100vw !important; }

the reason was, some rows only worked with the first class & some worked with the second one, plus for some reason, it did affect the English rows when I made them in theme-wide.

This is what I have
WordPress - version 5.0.2
Xstore Theme - 5.1.3 (child 1.0)
Polylang - Version 2.5
WPBakery Page Builder - Version 5.5.2

@kinti
Copy link

kinti commented Feb 6, 2020

Thank you very much

@ravismakwana
Copy link

Thank you so much

@bahmanpasha
Copy link

bahmanpasha commented Mar 24, 2020

dear friend
thank you for fixing this problem
do me a favor and please tell us to which file this script has to be added exactly

@fritexvz
Copy link

@serguk89 Thank you for the code. It finally working!
@WWGate Thank you for media CSS, working.

I am using WordPress 5.3.2 and WPBakery Page Builder 6.1.0, on Nginx (LEMP) with PHP 7.3 including plugins W3 Total Cache (page, browser, object, database + cloudflare setup) & Autooptimize (JS, HTML, CSS) and and CloudFlare Free Plan.

Do not know why it stopped working after upgrading WPBakery to the latest one, also switching on the better server -.-

Thanks again, solved my problem after a research and going crazy about it :D

@anasalpure
Copy link

anasalpure commented Dec 1, 2020

Hello
i tryed to improve this code

function bs_fix_vc_full_width_row() {
        if(jQuery('[data-vc-full-width="true"]:first').css( 'left' ) == 'auto') return;
        let rightAuto = jQuery('[data-vc-full-width="true"]:first').css( 'right' ) == 'auto' ;
        if( jQuery('html').attr('dir') == 'rtl' && !rightAuto){
            jQuery('[data-vc-full-width="true"]').each( function(i,v){
                jQuery(this).css('right' , jQuery(this).css('left') ).css( 'left' , 'auto');
            });
        }
    }

@laravelspa
Copy link

Hello
Only this code worked for me correctly

function bs_fix_vc_full_width_row(){
	 var $elements = jQuery('[data-vc-full-width="true"]');
	 jQuery.each($elements, function () {
		 var $el = jQuery(this);
		 $el.css('left', $el.css('right')).css('right', 'auto');
	 });
 }

@sindrome71
Copy link

You're the best @aliaghdam , saved my project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment