회원제 블로그 또는 사이트를 운영 중인 경우 어드민 바(Admin Bar)를 숨기고 싶은 경우가 있다.
회원 관리 플러그인을 통해 숨기는 방법, Admin Bar 전용 플러그인을 설치해 제어하는 방법 등 방법은 많지만 외부 기능에 기대지 않고 functions.php에 간단한 코드 추가로 숨길 수 있는 방법이 있어 기록한다.
다음 코드를 테마의 functions.php 파일에 추가하면 된다.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if ( ! current_user_can( 'administrator' ) ) { | |
add_filter( 'show_admin_bar', '__return_false' ); | |
} |
참고자료
참고 함수 :: current_user_can, show_admin_bar
읽어보면 좋은 정보 :: https://www.thewordcracker.com/basic/how-to-check-if-the-current-user-is-an-administrator-in-wordpress/