2

How to make the wordpress editor readonly like readonly inputs. i am using following code for to display the editor in the page

<?php
$args= array( 
'quicktags' => false,
'media_buttons' => false
);
wp_editor( wpautop(stripslashes($my_text)), "my_text", $args);
?>

any option available in its settings or any other method?

Mehar
  • 2,158
  • 3
  • 23
  • 46

1 Answers1

3

use can use tiny_mce_before_init to modify the tiny mce arguments to set it as readonly

add_filter( 'tiny_mce_before_init', function( $args ) {

    if ( 1 == 1 )
         $args['readonly'] = 1;

    return $args;
} );
Ram Sharma
  • 8,676
  • 7
  • 43
  • 56
  • may I ask why is the `1 == 1` if-condition necessary? – Orel Biton Sep 15 '14 at 15:34
  • 1
    @OrelBiton It's not. My guess is that the answerer wanted to show how you can use a conditional block to specify when a readonly content editor would be necessary. It's up to you to decide what those conditions actually are. – maiorano84 Apr 11 '16 at 16:16
  • I realise this is an old question but I have the same requirement and this answer is not working for me. I do not know if the timyMCE code has changed but the readonly attribute is not getting added to the textarea. I can see in the page source that it is getting as far as inclusion in the tinyMCEPreInit object, in a property named the same as the selector but the tinyMCE JS seems to do nothing with it. I also tried adding a readonly argument to the call wp_editor but that has no effect. – GeeC Sep 12 '19 at 05:47