$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>templates - How can I add text to a specific 'Edit Page'?|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

templates - How can I add text to a specific 'Edit Page'?

matteradmin9PV0评论

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?!

Share Improve this question asked Dec 16, 2018 at 11:29 CraigCraig 3581 gold badge2 silver badges20 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

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.

Post a comment

comment list (0)

  1. No comments so far