wpml language switcher shortcode

function language_switcher_fun( $atts ){
	return ob_get_clean();
add_shortcode( 'language_switcher_shortcode', 'language_switcher_fun' );

You can use it like this [language_switcher_shortcode]

Include category id in body_class() and post_class()

Use this code on your themes functions.php to add current category id on body and post

function category_id_class($classes) {
	global $post;
	foreach ((get_the_category($post->ID)) as $category)
		$classes[] = 'cat-' . $category->cat_ID . '-id';
	return $classes;
add_filter('post_class', 'category_id_class');
add_filter('body_class', 'category_id_class');

Set a maximum upload count for users on a specific user role

Use the following code to limit 10 upload for specific role

add_filter( 'wp_handle_upload_prefilter', 'limit_uploads_for_user_roles' );

function limit_uploads_for_user_roles( $file ) {
  $user = wp_get_current_user();
  // add the role you want to limit in the array
  $limit_roles = array('contributor');
  $filtered = apply_filters( 'limit_uploads_for_roles', $limit_roles, $user );
  if ( array_intersect( $limit_roles, $user->roles ) ) {
    $upload_count = get_user_meta( $user->ID, 'upload_count', true ) ? : 0;
    $limit = apply_filters( 'limit_uploads_for_user_roles_limit', 10, $user, $upload_count, $file );
    if ( ( $upload_count + 1 ) > $limit ) {
      $file['error'] = __('Upload limit has been reached for this account!', 'yourtxtdomain');
    } else {
      update_user_meta( $user->ID, 'upload_count', $upload_count + 1 );
  return $file;

This action will fire when user delete attachment

add_action('delete_attachment', 'decrease_limit_uploads_for_user');

function decrease_limit_uploads_for_user( $id ) {
   $user = wp_get_current_user();
   // add the role you want to limit in the array
   $limit_roles = array('contributor');
   $filtered = apply_filters( 'limit_uploads_for_roles', $limit_roles, $user );
   if ( array_intersect( $limit_roles, $user->roles ) ) {
     $post = get_post( $id);
     if ( $post->post_author != $user->ID ) return;
     $count = get_user_meta( $user->ID, 'upload_count', true ) ? : 0;
     if ( $count ) update_user_meta( $user->ID, 'upload_count', $count - 1 );

Thanks Giuseppe

Best ways to detect IE browser

IE6 is a worse dream for every web developers. Good news is that Software giant Microsoft has released a new website with the expressed aim of killing off its Internet Explorer 6 browser.


Still we have to deal with IE7 to IE9

Here is some way to cut down your development time by easily detecting IE.

IE Conditional Comments

It is the most commonly used to fix the IE bugs for specific versions (IE6, IE7, IE8,IE9)

// Target all version of IE
<!--[if IE]>
<link rel="stylesheet" type="text/css" href="all-ie.css" />
//Target everything except IE
<!--[if !IE]><!-->
	<link rel="stylesheet" type="text/css" href="not-ie.css" />
//Target IE 6 only
<!--[if IE 6]>
	<link rel="stylesheet" type="text/css" href="ie6.css" />
//Target IE 7 only
<!--[if IE 7]>
	<link rel="stylesheet" type="text/css" href="ie7.css">
//Target IE 8 and lower
<!--[if lt IE 9]>
	<link rel="stylesheet" type="text/css" href="ie8-and-down.css" />
<!--[if lte IE 8]>
	<link rel="stylesheet" type="text/css" href="ie8-and-down.css" />
//Target IE 8 and higher 
<!--[if gt IE 7]>
	<link rel="stylesheet" type="text/css" href="ie8-and-up.css" />
<!--[if gte IE 8]>
	<link rel="stylesheet" type="text/css" href="ie8-and-up.css" />

CSS Rules Specific

Its an way if you just want to do small changes on you css file in a quick way.

.wrapper {
background: red; /* standard */
background: green\9; /* IE 8 and below */
*background: blue; /* IE 7 and below */
_background: black; /* IE 6 */

Conditional HTML Class

Paul Irish found a way and it doesn’t cause any validation errors! I think this is best.

<!--[if lt IE 7 ]> <html class="ie6"> <![endif]-->
<!--[if IE 7 ]> <html class="ie7"> <![endif]-->
<!--[if IE 8 ]> <html class="ie8"> <![endif]-->
<!--[if IE 9 ]> <html class="ie9"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <html> <!--<![endif]-->

Hidden elements using HTML5

HTML5 introduce the hidden attribute, which will allow you to hide a specific element. So no need to use css display:none anymore!

<div hidden>You can't see this text.This is hidden by HTML5 hidden attribute.</div>

Source: http://html5demos.com/hidden

css only tooltip

Here is the html structure for tooltip

Lorem ipsum dolor sit

And here is the css styles

/* base CSS element */
.tip {
background: #eee;
border: 1px solid #ccc;
padding: 10px;
border-radius: 8px;
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
position: relative;
width: 200px;

/* arrows – :before and :after */
.tip:before {
position: absolute;
display: inline-block;
border-top: 7px solid transparent;
border-right: 7px solid #eee;
border-bottom: 7px solid transparent;
border-right-color: rgba(0, 0, 0, 0.2);
left: -14px;
top: 20px;
content: ”;

.tip:after {
position: absolute;
display: inline-block;
border-top: 6px solid transparent;
border-right: 6px solid #eee;
border-bottom: 6px solid transparent;
left: -12px;
top: 21px;
content: ”;

Source: http://davidwalsh.name/css…

Add logo to wordpress dashboard login without plugin

If you want to change the WordPress dashboard login logo then this piece of code can meet your requirement.

Just paste this code in the your theme functions.php

function custom_login_logo() {
    echo '<style type="text/css">
        h1 a { background-image:url('.get_bloginfo('template_directory').'/images/custom-login-logo.png) !important; }

add_action('login_head', 'custom_login_logo');