readonly()WP 4.9.0

Deprecated from version 5.9.0. It is no longer supported and can be removed in future releases. Use wp_readonly() introduced in 5.9.0 instead.

Outputs the html readonly attribute.

Compares the first two arguments and if identical marks as readonly.

This function is deprecated, and cannot be used on PHP >= 8.1.

No Hooks.


String. HTML attribute or empty string.


readonly( $readonly_value, $current, $display );
$readonly_value(mixed) (required)
One of the values to compare.
The other value to compare if not just true.
Default: true
Whether to echo or just return the string.
Default: true



#1 Let's add the readonly attribute

Suppose you want to add a readonly value to the field if the current user can't edit post 25:

<input type='text' name='myname' value='Value' <?php readonly( current_user_can('edit_post', 25 ) ?> />



Since 4.9.0 Introduced.
Deprecated since 5.9.0 Use wp_readonly() introduced in 5.9.0.

readonly() code WP 6.5.3

function readonly( $readonly_value, $current = true, $display = true ) {
	_deprecated_function( __FUNCTION__, '5.9.0', 'wp_readonly()' );
	return wp_readonly( $readonly_value, $current, $display );