Tuesday, December 16, 2014

Hide tabs in wordpress backend if user is not admin

This simple and easy script will hide the media tab in the backend of wordpress if the current user that is logged-in is not admin.
we use css to hide the tabs.
if ( !is_super_admin() ) {
 add_action('admin_head', 'hideElement');
 function hideElement() {
   echo '<style>
   #menu-media{
    display:none !important;
   }    
    </style>';
 }
}
note that this method is not the best way to hide the tabs in our wordpress backend. It is not bulletproof and secure.

Run a css depending on the current logged in username

This script will add custom css on our wordpress backend if the current logged in user name is "guest".

$current_user = wp_get_current_user();
if ( $current_user->user_login == "guest" ) {
 add_action('admin_head', 'hideMenus');
 function hideMenus() {
   echo '<style>
   #menu-media,#menu-comments,#menu-users,#menu-posts{
    display:none !important;
   }    
    </style>';
 } 
}


Friday, December 12, 2014

Get the width and height of a div using jquery

This code shows how to get the width and height of a container, We must know the css selector of the div in order to do this.
//get the class or id of the container
 $('.container').width();
 $('.container').height();

Thursday, December 4, 2014

Add button next to add media in create post wordpress

PREVIEW:


// add button next to add media button
function add_my_media_button() {
    echo 'Custom button next to Add media';
}
add_action('media_buttons', 'add_my_media_button');

Tuesday, December 2, 2014

Social media sliding menu on hover using css only

This social media menu is purely css3.
Preview:
We used css3 for the transition and font awesome for the icons.
note: You can copy the css codes on the css tab of the live demo(js fiddle).