Set Post Title to Read-only and Disable Permalink Slug Editor in Gutenberg

I used this, inline, on specific pages (using get_current_screen()). I’d hoped this would enable me to hide/show the permalink panel under certain conditions. However, removeEditorPanel() removes the permalink panel globally. This isn’t completely horrifying, since the css still works conditionally, and the permalink can still be edited via the editor (by clicking on the title) everywhere else. Hoping the Gutenberg documentation/options get better soon. If anyone has any suggestions, I’m all ears…

add_action( 'admin_footer', function() {
$screen = get_current_screen();
if ( $screen->id == 'WUTEVA' ) { ?>
<style>
  .editor-post-permalink{display: none !important;}
</style>
<script type="text/javascript">
  const { removeEditorPanel } = wp.data.dispatch('core/edit-post');
  removeEditorPanel( 'post-link' );
</script>
<?php }
} );

Leave a Comment

tech