display this widget only for admin

wp-content/themes/sidebar.php

You can determine if the current user is an administrator by checking if they have access to one of the admin-only privileges:

if ( current_user_can('manage_options') ) {
    //code to display your widget
}

* The sidebar contains the main widget area.

what are current_user_can () function parameters ?

 

 

Administrator

The capabilities of Administrators differs between single site and Multisite WordPress installations. All administrators have the following capabilities:
http://codex.wordpress.org/Roles_and_Capabilities#Capabilities

//OK SOLUTION:

This works only for Theme TwentyTen:

 

use the Secondary Widget Area:

sidebar.php

<?php

// WAUTOM: only if admin users: only admin users have right to “install_themes” etc
// http://codex.wordpress.org/Roles_and_Capabilities

// A second sidebar for widgets, just because.
if ( is_active_sidebar( ‘secondary-widget-area’ ) && current_user_can(‘install_themes’) ) : ?>

<div id=”secondary” role=”complementary”>
<ul>
<?php dynamic_sidebar( ‘secondary-widget-area’ ); ?>
</ul>
</div><!– #secondary .widget-area –>

<?php endif; ?>

 

 

 

 

 

By EVS

Leave a Reply

Please Login to comment
  Subscribe  
Notify of