- Status
- Resolved by author
- Resolved in
- Bricks 2.3
- Related plugin/theme
- Bricks Theme
Overview of the issue
When using Bricks with WPML, you might experience an issue where opening the Bricks editor for the default language redirects to an incorrect URL with an extra language directory, which results in a 404 error. This can happen when WPML is set to use directory for default language.
Workaround
Workaround 1
Easy Fix (no code)
- Go to Bricks > Settings > Builder
- Set the builder language to “Site Default” and save
Workaround 2
Please, make sure of having a full site backup of your site before proceeding.
- Add the following code to your theme’s functions.php file.
add_action( 'after_setup_theme', function () { if ( ! defined( 'ICL_SITEPRESS_VERSION' ) || ! class_exists( 'BricksTheme' ) ) { return; } $bricks = BricksTheme::instance(); // 1. Prevent Bricks from switching language if ( ! empty( $bricks->wpml ) ) { remove_action( 'bricks/builder/switch_locale', [ $bricks->wpml, 'switch_builder_languge' ] ); } // 2. Instead switch UI locale add_action( 'bricks/builder/switch_locale', function ( $locale ) { if ( empty( $locale ) || empty( $_GET['bricks'] ) || $_GET['bricks'] !== 'run' ) { return; } // prevent memory exhausion I got on my sandbox static $lock = false; if ( $lock ) { return; } $lock = true; try { // Switch UI locale switch_to_locale( $locale ); // Reload Bricks theme textdomain unload_textdomain( 'bricks' ); load_theme_textdomain( 'bricks', get_template_directory() . '/languages' ); } finally { $lock = false; } }, 5, 1 ); }, 20 );