ワードプレスのテーマtwentytwentyを基盤に、管理者画面の投稿編集画面に表示されるパーマリンクを非表示にする実装を行ったので、備忘録的にこの記事を残す。
環境情報
PHP:version 7.3.12
WordPress:version 5.5.3
WPテーマ:twentytwenty
パーマリンクの非表示
下記の内容をテーマの中にある「functions.php」に追記して「if文」の中の「post_type_name」の部分を実際に使用しているカスタム投稿名に変えれば投稿編集画面の「パーマリンク」の項目は表示されなくなります。
functions.php
add_action('current_screen','hide_permalink');
function hide_permalink(){
$current_screen = get_current_screen();
if(isset($current_screen) && $current_screen->post_type === 'post_type_name') {
$style = '<style>#edit-slug-box {display: none !important; }</style>';
echo $style;
}
}