Skip to content

Instantly share code, notes, and snippets.

@idokd
Created August 26, 2022 08:23
Show Gist options
  • Select an option

  • Save idokd/4bb393b18e4cf8b27b91474de6b6e7db to your computer and use it in GitHub Desktop.

Select an option

Save idokd/4bb393b18e4cf8b27b91474de6b6e7db to your computer and use it in GitHub Desktop.
WordPress Guteberg for RTL swticher
<?php
// When you like your admin in LTR but you have to edit a gutenberg page that is in hebrew or arabic that is RTL,
// and to avoid switching the user language, just paste this code on your functions.php and on the url of the edit page add
// the query param: dir=rtl and from there on the gutenberg editor area will keep RTL
// if you wish to all content to display in certain direction
define( 'VISUAL_EDITOR_DEFAULT_DIRECTION', 'rtl' );
// Set RTL to post for Gutenberg Editor to keep RTL
add_action( 'admin_print_styles', function() {
$dir = sanitize_text_field( $_GET[ 'dir' ] );
$post_id = sanitize_text_field( $_REQUEST[ 'post' ] );
if ( is_admin() && current_user_can( 'edit_post' ) && $dir ) {
update_post_meta( $post_id, 'direction', $dir );
}
$dir = get_post_meta( $post_id, 'direction', true ) ? : ( defined( 'VISUAL_EDITOR_DEFAULT_DIRECTION' ) ? VISUAL_EDITOR_DEFAULT_DIRECTION : null );
if ( !$dir ) return;
?><style id="visual-editor-lang-direction">
.edit-post-visual-editor {
direction: <?php echo $dir ?>;
}
</style><?php
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment