0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

WordPressでパーマリンクの非表示化

Last updated at Posted at 2020-12-08

ワードプレスのテーマ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;
    }
}
0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?