I have a specific Page, that I do not wish to be edited. As such, I would like to place a 'Do Not Edit This Page' message within a specific 'Edit Page' file as follows:
Any ideas on how this can be achieved or what I could search for within the WordPress Codex/Developer Resource? Ideally, I would like to be able to create some sort of Template File but if not, I guess the solution would involve the use of Hooks within the functions.php
file?!
I have a specific Page, that I do not wish to be edited. As such, I would like to place a 'Do Not Edit This Page' message within a specific 'Edit Page' file as follows:
Any ideas on how this can be achieved or what I could search for within the WordPress Codex/Developer Resource? Ideally, I would like to be able to create some sort of Template File but if not, I guess the solution would involve the use of Hooks within the functions.php
file?!
To do this you would indeed have to include some code in the functions.php
of your theme. You can use admin_notices
to add a note to this specific page like this:
add_action( 'admin_notices', 'wpse332074_donotedit' );
function wpse332074_donotedit () {
$screen = get_current_screen();
if ($screen->post_type == 'page') {
$variable = $_GET['post'];
if ($variable == id_of_page_as_integer) {
$class = 'notice notice-error';
$message = __( 'Do not edit this page!', 'your-text-domain' );
echo '<div class="' . $class . '"><p>' . $message . '</p></div>';
}
}
}
However, this would allow people to ignore the message and still edit the page. If you really don't want the page to be edited, you can remove the edit, quick edit and trash links in the all pages screen by using the page_row_actions
filter:
add_filter( 'page_row_actions', 'wpse332074_disable_edit', 10, 2 );
function wpse332074_disable_edit ($actions, $post) {
if ( $post->ID == id_of_page_as_integer ) {
unset( $actions['edit'] );
unset( $actions['inline hide-if-no-js'] );
unset( $actions['trash'] );
}
return $actions;
}
Beware that any changes to functions.php
will be lost when the theme is updated. The proper way to do this is to build a child theme.