Use the action hook edit_form_after_title
The display:none
rule might cause some JS issue so it might be best to use visibility:hidden
so the element is still accessible to whatever scripts in the DOM.
This condition will hide the form fields and show the title and URL statically.
add_action('edit_form_after_title', function($post) {
if( !empty($post->post_title) && !current_user_can('manage_options') ) {
echo '<style>#titlediv {visibility: hidden !important; height: 1px !important;}</style>';
echo '<h2>'.$post->post_title.'</h2>';
echo '<a href="'.get_site_url()."https://wordpress.stackexchange.com/".$post->post_name.'">'.get_site_url()."https://wordpress.stackexchange.com/".$post->post_name.'</a>';
}
});
Note that post titles can also be edited within table list view with quick edit so you’ll need to hook into that location also and do the same.
Since your concern is search engine 404 related, you might wanna consider disabling a lot more which could change the post’s URL or accessibility:
- move to trash
- category change
- post privacy
- publish state
- publish date change
Also if yo use a third party visual composer like Elementor or similar, those may still allow title change and not use the ID used by WP core system.
Post object returned by var $post
new post
WP_Post Object
(
[ID] => 369
[post_author] => 1
[post_date] => 2023-09-22 18:19:21
[post_date_gmt] => 0000-00-00 00:00:00
[post_content] =>
[post_title] =>
[post_excerpt] =>
[post_status] => auto-draft
[comment_status] => closed
[ping_status] => closed
[post_password] =>
[post_name] =>
[to_ping] =>
[pinged] =>
[post_modified] => 2023-09-22 18:19:21
[post_modified_gmt] => 0000-00-00 00:00:00
[post_content_filtered] =>
[post_parent] => 0
[guid] => https://example.net/?page_id=369
[menu_order] => 0
[post_type] => page
[post_mime_type] =>
[comment_count] => 0
[filter] => raw
)
saved post edit mode
WP_Post Object
(
[ID] => 274
[post_author] => 1
[post_date] => 2023-09-11 03:55:29
[post_date_gmt] => 2023-09-11 07:55:29
[post_content] => there is always stuff to write
[post_title] => The Page
[post_excerpt] =>
[post_status] => publish
[comment_status] => closed
[ping_status] => closed
[post_password] =>
[post_name] => the-page
[to_ping] =>
[pinged] =>
[post_modified] => 2023-09-22 18:08:33
[post_modified_gmt] => 2023-09-22 22:08:33
[post_content_filtered] =>
[post_parent] => 0
[guid] => https://example.net/?page_id=274
[menu_order] => 0
[post_type] => page
[post_mime_type] =>
[comment_count] => 0
[filter] => edit
)