Skip to content

Instantly share code, notes, and snippets.

@lilumi
Created April 8, 2023 14:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lilumi/c2d76d26e885b6c02360c9faaebf6ee2 to your computer and use it in GitHub Desktop.
Save lilumi/c2d76d26e885b6c02360c9faaebf6ee2 to your computer and use it in GitHub Desktop.
Disable WPML String Translations for Gutenberg Blocks
<?php
/*
WPML checks for gutenberg like this:
\WPML_Page_Builders_Defined->has()
```
if ( 'gutenberg' === $page_builder ) {
if ( version_compare( $wp_version, '5.0-beta1', '>=' ) ) {
return true;
}
}
```
so I created a hooks to override $wp_version during this checks.
*/
add_action('after_setup_theme', 'lm_init_wpml');
function lm_init_wpml() {
add_action('wpml_load_page_builders_integration', 'lm_disable_wpml_gutenberg_integration_before', 9);
add_action('wpml_load_page_builders_integration', 'lm_disable_wpml_gutenberg_integration_after', 11);
}
function lm_disable_wpml_gutenberg_integration_before() {
global $wp_version, $site_wp_version;
$site_wp_version = $wp_version;
$wp_version = 3; // anything lower than 5.0-beta1
}
function lm_disable_wpml_gutenberg_integration_after() {
global $wp_version, $site_wp_version;
$wp_version = $site_wp_version;
unset($site_wp_version);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment