Site icon Coding Dude

[SOLVED]Problems with qTranslate and Fusion Page Builder (Avada theme)

Working on a huge project for RiskRhino I’m developing their websites using the Avada theme for WordPress. Since RiskRhino is a company based in the Netherlands it was necessary to add a Dutch version to the site. Implementing this turned out to be quite a challenge as the free translation plugins available out there is quite limited. Eventually I chose qTranslate X, but to my surprise I found out that qTranslate and fusion page builder (Avada theme) do not go well together. After some head scratching and other web development and programming techniques I’ve figured out how to go around this problem.

qTranslate and Fusion Page Builder – the problem

Apparently, when using the Fusion Page Builder that comes with Avada, when you save a post or page the qTranslate X plugin gets confused and does not know how to properly set the language markers that it uses (ex. [:en] for English, [:nl] for Dutch). The plugin assumes that the Default post/page editor is in use and it only knows how to work with that.

So, when saving a post or page from the Fusion Page Builder the content for both languages gets stored every time. Everytime you save the content gets duplicated.

The work around: If before saving a post or page you switch to the Default editor and save, then all goes well. The problem I had was that merely informing the editors about this workaround is not enough, and if one of them forgets about switching to the Default editor then your content will get messed up. So, I had to find a way to enforce this way of working.

qTranslate and Fusion Page Builder – the solution

My solution was to create a plugin that automatically switches to the Default editor right before saving. This way you make sure that the translations are properly saved. The code for the plugin is short and straight to the point:

<?php
/*
Plugin Name: Fusion Page Builder & qTranslate-X
Description: To make both plugins work together by restoring page to default editor before save.
Author: Coding Dude
Author URI: //www.coding-dude.com/wp/web-design/wordpress/solved-problems-with-qtranslate-and-fusion-page-builder-avada-theme/
*/

function bapro_admin_inline_js(){
 echo "<script type='text/javascript'>\n";
 echo
"function fixQTranslate(){
 //when user goes with the mouse over the Update button
 jQuery(\"input[name='save']\").hover(".
"function(){
 //if the fusion page builder is active
 if(fusionBuilderState == 'active'){
 var _ypos = window.scrollY;
 //click to switch to the Default editor
 jQuery( '#fusion-pb-switch-button' ).click();
 //scroll to the same position as before the Default editor was active
 window.scrollTo(0,_ypos);
 };
 });
};
//after the editor page is fully loaded add the fix
document.addEventListener(\"DOMContentLoaded\", fixQTranslate);";
 echo "\n</script>";
}

//add some inline JS in the admin area
add_action( 'admin_print_scripts', 'bapro_admin_inline_js' );
?>

 

Exit mobile version