특정 사용자 역할일 경우 내용 표시 기능 관련 질문

안녕하세요. 숏코드를 활용하여 시작태그와 종료태그 사이의 내용을 특정 Role에게만 보이도록 하고자,

아래 링크를 참고하여 제 자식테마 function.php에 다음과 같은 코드를 삽입했습니다.

https://stackoverflow.com/questions/39593273/user-roles-shortcode

function check_user_role( $atts, $content = null ) {
  extract( shortcode_atts( array(
          'role' => 'role' ), $atts ) );

  $user = wp_get_current_user();
  $allowed_roles = explode(',', $role);
  if( array_intersect($allowed_roles, $user->roles ) ) {
          return $content;
  }
}
add_shortcode( 'user_role', 'check_user_role' );

/* 숏코드 사용법
[user_role role="begginer"]content[/user_role]
*/

 

CSS의 display: none; 처럼 아예 DIV 요소가 공간차지도 없이 사라지길 원했지만, 아래 사진처럼 공백으로 자리를 차지하면서 보이지 않게 되어버립니다.

https://imgur.com/a/6aQ2pTm

(사진은 3개의 요소 중 가운데 요소가 위의 코드로 인해 감춰진 경우입니다)

$content = null 이 수식 때문에 그런 것 같은데,

어떻게 해야 display:none;처럼 아예 공간차지도 안 하고 없어지게 할 수 있을까요?

 

 

 

워드프레스 에러 기술지원 서비스 전문가에게 맡기세요
워드프레스 에러 기술지원 서비스 전문가에게 맡기세요
좋은 정보와 인맥을 동시에, 워드프레스 사용자 단톡방 참여하기