wordpress snippets last updated   : April 22, 2014
we now have 631 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.
[/access]
source →
jqsnipp.com | we just launched jquery snippets website