12 February 2014

Remove Height & Width Attributes From Images In Wordpress

WordPress will automatically add the image Width and Height attribute in the image element.

If you want to remove height and width attributes from the image elements it can be done with the following filters:-
  • post_thumbnail_html - Filter any post thumbnails.
  • image_send_to_editor - Filter the HTML when adding a image to the editor.

Add this code into your theme's `functions.php` file.

add_filter( 'image_send_to_editor', 'remove_attribute_from_image', 10 );
add_filter( 'post_thumbnail_html', 'remove_attribute_from_image', 10 );
add_filter( 'get_image_tag', 'remove_attribute_from_image', 10 );

function remove_attribute_from_image( $html )
{
 return preg_replace( '/(width|height)="\d*"\s/', "", $html );
}

Have Fun!

4 February 2014

How to add notification bubble to Wordpress admin menu


Following process will add pending post count in admin menu items..
You also can change as your need..

Edit the theme's `function.php` and add following line of code :-

First, add hook to admin menu
//Add hook to Admin Menu.
add_action('admin_menu', 'notification_count_in_admin_menu');

Now add function that will alter you menu with notification count.
function notification_count_in_admin_menu()
{
    global $menu;
    $post_types = array('post', 'page', 'your_cpt');
    foreach ($post_types as $type)
    {
        $post_count = get_number_of_pending_post_by_type($type);
        if(!empty($post_count))
        {
            foreach ( (array)$menu as $key => $parent_menu )
            {
                if ( $parent_menu[2] == 'edit.php?post_type='.$type )
                {
                    $menu[$key][0] = $menu[$key][0]. ''.$post_count.'';
                }
            }
        }
    }
}
function get_number_of_pending_post_by_type($type)
{
    global $wpdb;
    return $wpdb->get_var( "SELECT COUNT(ID) as count FROM {$wpdb->post} WHERE `post_status`='pending' AND `post_type`='{$type}';" );
}

Have fun!