wordpress snippets last updated   : January 29, 2015
we now have 646 snippets

Display content based on user capability

wordpress snippet

Adding the first snippet to the functions.php of your wordpress will let you display content base on user capability. Use the second snippet in your posts with the corresponding capability. View the codex for more information on capabilities Great little snippet By Justin Tadlock.

snippet :  PHPcopy
add_shortcode( 'access', 'access_check_shortcode' );
function access_check_shortcode( $attr, $content = null ) {
	extract( shortcode_atts( array( 'capability' => 'read' ), $attr ) );
	if ( current_user_can( $capability ) && !is_null( $content ) && !is_feed() )
		return $content;
	return '';
source →
snippet :  SHORTCODEcopy
[access capability="switch_themes"]
The currently logged-in user is a god on this site.
source →

Did you like this post? If so please share it with your friends. Thanks!