admin管理员组文章数量:1130349
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?!
1 Answer
Reset to default 2To 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.
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?!
1 Answer
Reset to default 2To 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.
本文标签: templatesHow can I add text to a specific 39Edit Page39
版权声明:本文标题:templates - How can I add text to a specific 'Edit Page'? 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749091826a2314639.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论