EN / ZH
Making Specific Content Visible Only to Administrators in WordPress

If you want certain content in WordPress to be visible only to administrators, you can achieve this by adding a simple shortcode. Add the following code to your theme’s functions.php file:

add_shortcode( 'member', 'member_check_shortcode' );
function member_check_shortcode( $atts, $content = null ) {
if ( is_user_logged_in() && !is_null( $content ) && !is_feed() )
return $content;
return '';
}

Then, when writing a post, you can use the following shortcode format to wrap the content you want visible only to administrators:

[member]Content you want visible only to administrators[/member]

This way, only logged-in administrators will be able to see the content wrapped in the [member] shortcode, while all other visitors will see nothing.