Preview the Site in Right-to-Left Mode
Lets administrators add ?wpide_rtl=1 to any URL to see the site and dashboard laid out right-to-left, so themes can be checked for Arabic or Hebrew without switching the site language.
Opens WPIDE on
Code
add_action( 'init', function () {
if ( empty( $_GET['wpide_rtl'] ) || ! current_user_can( 'manage_options' ) ) { // phpcs:ignore WordPress.Security.NonceVerification
return;
}
global $wp_locale;
if ( $wp_locale instanceof WP_Locale ) {
$wp_locale->text_direction = 'rtl';
}
} );
add_action( 'admin_bar_menu', function ( $bar ) {
if ( empty( $_GET['wpide_rtl'] ) || ! current_user_can( 'manage_options' ) ) { // phpcs:ignore WordPress.Security.NonceVerification
return;
}
$bar->add_node( array(
'id' => 'wpide-rtl',
'title' => 'RTL preview: on',
'href' => remove_query_arg( 'wpide_rtl' ),
) );
}, 100 );
Notes
Only affects the logged-in administrator making the request. Add ?wpide_rtl=0 or remove the parameter to go back.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.