WordPress 3.8 arrives with redesigned dashboard, new theme and widget screens, vector-based icons, and many more

WordPress.org announced the debut of WordPress 3.8, which introduces a modern new design that the company calls its “most beautiful update yet.” You can download the new release now from WordPress.org/Download (it’s 6.10MB).

Dubbed “Parker” in honor of American jazz saxophonist and composer Charlie Parker, WordPress 3.8 brings a new look to the entire admin dashboard.

WordPress 3.8, WordPress King Praveen Singh Shekhawat

The new features are as follows:

  • Modern aesthetic: The new WordPress dashboard has a fresh, uncluttered design that embraces clarity and simplicity.
  • Clean typography: The Open Sans typeface provides simple, friendly text that is optimized for both desktop and mobile viewing. It’s even open source, just like WordPress.
  • Refined contrast: With superior contrast and large, comfortable type, the new design is easy to read and a pleasure to navigate.
  • High definition at high speed: WordPress is sharper than ever with new vector-based icons that scale to your screen. By ditching pixels, pages load significantly faster, too.
  • Admin color schemes: WordPress now includes eight new admin color schemes, which can be previewed and changed from your Profile page.
  • Refined theme management: The new themes screen lets you survey your themes at a glance. Click to add more information, and use your keyboard’s navigation arrows to flip through themes.
  • Smoother widget experience: The widgets screen has been streamlined. On large monitors, multiple widget areas stack side-by-side to use the available space while on tablets, just tap a widget to add it.
  • Twenty Fourteen: Turn your blog into a magazine with this new theme. Choose a grid or a slider to display featured content on your homepage. Customize your site with three widget areas or change your layout with two page templates.

WordPress 3.8 Colors, WordPress King Praveen Singh Shekhawat

Improve loading, Remove unnecessary scripts and styles in WordPress

Some of the plugins, when installed, add 2 or 3 scripts and stylesheets to every page on website. This isn’t necessarily a problem but it would be nice to have scripts loaded only on pages that actually need them.

Let’s take a example of the most popular Contact Form 7 plugin. Most likely, only pages that contain the

 [contact-form-7] 

shortcode will need the extra scripts and styles.

The following code will check your post content to see if it contains the contact form 7 shortcode. If it doesn’t, it will dequeue the styles and scripts so they will not be loaded.

function pv_dequeue_scripts() {
    
    $load_scripts = false;

    if( is_singular() ) {
    	$post = get_post();

    	if( strstr($post->post_content, '[contact-form-7 ') ) {
        	$load_scripts = true;
    	}

    }

    if( ! $load_scripts ) {
        wp_dequeue_style( 'contact-form-7' );
        wp_dequeue_script( 'contact-form-7' );
    }

}

add_action( 'wp_enqueue_scripts', 'pv_dequeue_scripts');

You can, of course, add more logic to the function to detect the necessity of scripts for other plugins as well. You will need to know the handles used to identify the scripts and styles of the plugin and the shortcode.

Be careful when implementing this though. If you’re rendering a contact form using a widget or template function (for example), the code above won’t detect it and will still dequeue the scripts and styles.

Add a Custom Post Type Submenu To Another Post Type Menu

Custom Post Types are the most powerful features of WordPress, specially if you’re in the business of creating custom solutions for clients beyond normal bloging functionality.

Introducing a new menu in the WordPress dashboard is really easy when using the custom post type API; however, what about the case when you have a custom post type and is a child of another post type?

Specifically, what about the case when you want to add a custom post type submenu to an existing post type menu?

First, let’s introduce a Testimonial custom post type. This will be a top-level menu in the WordPress dashboard.

 /**
        * Define the 'Testimonial' post type.
        *
        * This will be our top-level custom post type menu.
        */
        $args = array(
        'labels'    =>    array(
        'all_items'    =>    'All Testimonial',
        'menu_name'    =>	'Testimonial',
        'singular_name'       =>	'Testimonial',
        'edit_item'           =>	'Edit Testimonial',
        'new_item'            =>	'New Testimonial',
        'view_item'           =>	'View Testimonial',
        'items_archive'       =>	'Testimonial Archive',
        'search_items'        =>	'Search Testimonial',
        'not_found'	          =>	'No testimonial found',
        'not_found_in_trash'  =>	'No testimonial found in trash'
        ),
        'supports'		=>	array( 'title', 'editor', 'author', 'revisions' ),
        'menu_position'	=>	5,
        'public'		=>	true
        );
        register_post_type( 'testimonial', $args );
    

Now, we can introduce a second post type, say, Client that will be used to represent all of the locations that we’ve used throughout the testimonial.

        /**
        * Next, we'll define a second custom post type called 'Client' where we could
        * potentially display a list of client that are used as part of our testimonial.
        *
        * This custom post type will be added as a submenu to the 'Client' menu<br>
        */
        $args = array(
        'labels'    =>	array(
        'all_items'           =>    'Client',
        'menu_name'	          =>    'Client',
        'singular_name'       =>    'Client',
        'edit_item'           =>    'Edit Client',
        'new_item'            =>    'New Client',
        'view_item'           =>    'View Client',
        'items_archive'       =>    'Client Archive',
        'search_items'        =>    'Search Client',
        'not_found'	          =>    'No client found.',
        'not_found_in_trash'  =>    'No client found in trash.'
        ),
        'supports'        =>    array( 'title', 'editor', 'revisions' ),
        'show_in_menu'    =>    'edit.php?post_type=testimonial',
        'public'		  =>    true
        );
        register_post_type( 'testimonial', $args );
    

Note that the following line is key in adding the menu as a submenu:

        'show_in_menu'    =>    'edit.php?post_type=testimonial', 
        /* 
        * testimonial is post type. you can change it as you want.
        */
    

Paginate WordPress posts with a thumbnail image

Its always nice to give your website users the ability to paginate through your posts, and there are a couple of simple inbuilt functions that will allow you to do so from with in the individual posts, by that I mean these functions should be used on the single.php template or single-{post-type}.php template.

By using get_previous_post() and get_next_post() you can retrieve all the information you need from the previous. If you want to find out more go checkout the codex in the links provided for both functions.

Using the following you can output the link to the previous post of the currently viewed post:

<?php
/*
 * get_previous_post() will return previous post full details in a object.
 * get_permalink() will return permalink of given post ID.
 */
$previous = get_previous_post();
echo get_permalink($previous->ID);
?>

using the get_next_post() you can do the same to get the opposite or get the next post of the currently viewed post like so:

<?php
/*
 * get_next_post() will return next post full details in a object.
 * get_permalink() will return permalink of given post ID.
 */
$next = get_next_post();
echo get_permalink($next->ID);
?>

Now that you can access the ID of the previous and next post we can use another function to get the thumbnail of those posts using the get_the_post_thumbnail() function like this:

<?php
/* get_the_post_thumbnail() will return post thumbnail */
echo get_the_post_thumbnail($previous->ID, 'thumbnail');
?>
<!-- or -->
<?php
/* get_the_post_thumbnail() will return post thumbnail */
echo get_the_post_thumbnail($next->ID, 'thumbnail');
?>

All you need to do now is to wrap the code up in your mark up to make it your own, putting it all together it might look something like this:

<?php
    $previous = get_previous_post();
    $next = get_next_post();
?>
<div class="paginateDiv">
    <div class="previous">
        <a title="<?php echo esc_attr($previous->post_title); ?>" href="<?php echo get_permalink($previous->ID); ?>">
            <?php echo get_the_post_thumbnail($previous->ID, 'thumbnail'); ?>
        </a>
    </div>
    <div class="next">
        <a title="<?php echo esc_attr($next->post_title); ?>" href="<?php echo get_permalink($next->ID); ?>">
            <?php echo get_the_post_thumbnail($next->ID, 'thumbnail'); ?>
        </a>
    </div>
</div>

Your html markup and css should be modified for your own designs but as long as you are on the single.php template then your users will now be able to paginate WordPress posts with a thumbnail image of the previous and next posts.

Show Custom Post Types on the Homepage

Custom post types are commonly used in WordPress sites, but they don’t show on the homepage or in the archive pages unless you write code to do that. I’ve put together some code that is smart about detecting your public custom post types and automatically adding them to your homepage and archive pages:

/**
 * Show WordPress custom post types on the main blog and archive pages
 **/
function show_my_post_types( $query ) {

  // Show all custom post types on main blog and archive pages
  if ( $query->is_main_query() && ( is_home() || ( is_archive() && !is_post_type_archive() ) ) ) {

    $custom_post_types = get_post_types( array(
       'public' => true,
       '_builtin' => false,
    ) );

    $post_types = array_merge( array('post'), $custom_post_types );
    $query->set( 'post_type', $post_types );
   }

   return $query;
}

add_filter( 'pre_get_posts', 'show_me_post_types' );

Enable Automatic Updates for WordPress Themes and Plugins

With version 3.7 WordPress introduced automatic updates. By default, these are on for maintenance and security releases only, but the underlying code is smart enough to support updates for themes and plugins. Here’s a simple code that will enable automatic updates for themes:

add_filter( 'auto_update_theme', '__return_true' );

And here’s one for plugins:

add_filter( 'auto_update_plugin', '__return_true' );

Please copy above code and past into theme function file.

WordPress 3.6: What’s new, and why it Batters

A New User Interface to Create Menus

Many of users often found Menus confusing. WordPress 3.6 comes with a new and simpler user interface to create and edit menus for your website. It has two tabs, one for editing menus and another to manage locations. This new interface is easy to use, and i think many users would find it refreshing too.

New UI for Menu System in WordPress 3.6
New UI for Menu System in WordPress 3.6

Log in Notifications

Sometimes your WordPress session may expire while you are working on the site. This could happen due to several reasons, an expired or deleted session cookie, administrator changing security keys, etc. With earlier versions of WordPress this meant that you will have to go back and log in again. This resulted into loss of important and unsaved changes. WordPress 3.6 resolves this issue by displaying log in notification when a user’s session expires. It opens the notification in a pop-window darkens the screen you were working at.

Improved session handling with log in notifications in WordPress 3.6
Improved session handling with log in notifications in WordPress 3.6

Improved Auto-save Feature

You will not have to worry about loosing content when working on a post. WordPress 3.6 comes with improved auto-save functionality. The most notable improvement to auto-save feature is that WordPress now utilizes your browser’s storage as well as WordPress database to save revisions. WordPress tries to match the current revision with the backup stored in your browser storage and notifies you if it finds any difference.

WordPress 3.6 Autosave feature utilizes browser storage to autosave posts
WordPress 3.6 Autosave feature utilizes browser storage to autosave posts

New Improved Revision Comparison

With WordPress 3.6 comes another great feature, the ability to compare post revisions. As you know that WordPress automatically saves post revisions. You can disable post revisions but over the years we have found this to be a very useful feature. One thing that we didn’t like was that it was difficult to quickly find differences between two revisions. With 3.6, WordPress displays post revisions and highlights the changes between two versions of an article. There is also a slider bar at top so you can easily switch between revisions.

Improved post revisions in WordPress 3.6
Improved post revisions in WordPress 3.6

Twenty Thirteen – The New Default Theme

WordPress 3.6 also comes with a new default theme Twenty Thirteen which is unlike any other default theme before. Unlike its predecessors, Twenty Thirteen is a little bold and more colorful. It is developed to showcase the power of post formats and all new features of WordPress 3.6. It is a responsive theme and designed to be fully accessible so that it can also be used by people with special needs.

Twenty Thirteen - The New Default Theme in WordPress 3.6
Twenty Thirteen – The New Default Theme in WordPress 3.6

Let us know what you think of new features and UI changes in WordPress by leaving a comment below.

How to track Post Hits by Using WordPress Post Meta without plugin.

This is a small trick, any one can use this trick in wordpress theme.

Just open your wordpress thme function file “function.php”. And put bellow functions into your function file.

//Track your post views without a plugin using 
function getPostViews($postID){
    $meta_key = 'post_views_count';
    $count = get_post_meta($postID, $meta_key, true);
    if($count==''){
        delete_post_meta($postID, $meta_key);
        add_post_meta($postID, $meta_key, '0');
        return "0 View";
    }
    return $count.' Views';
}
function setPostViews($postID) {
    $meta_key = 'post_views_count';
    $count = get_post_meta($postID, $meta_key, true);
    if($count==''){
        $count = 0;
        delete_post_meta($postID, $meta_key);
        add_post_meta($postID, $meta_key, $count);
    }else{
        $count++;
        update_post_meta($postID, $meta_key, $count);
    }
}

The above functions’ will create a custom field called ‘post_views_count’ attached to the ID of a post that will record the data but, if we have no data a then it will create it as zero (0).

To take advantage of the function we need to add the function into wordpress post detail page or custom post type detail page.

setPostViews(get_the_ID());

To show the post hits please put bellow code with post ID, where you want to post hits.

getPostViews(get_the_ID());

Disable Post Revisions in WordPress and Reduce Database Size

Post revisions is a great feature that WordPress has to offer but for some users it might not be the best option. For users who have limited database space, or for users creating WordPress as a CMS where they don’t need autosave, they can simply disable Post Revisions feature in WordPress by following this tutorial. By reducing the database size, you can also speed up your site.

Open wp-config.php located in your WordPress root directory and add the following

 define('AUTOSAVE_INTERVAL', 600 ); // seconds
define('WP_POST_REVISIONS', false ); 

This code will disable all future revisions to be saved and it will also increase your autosave interval from 60 seconds to 600 seconds, so it means your post will be autosaving every 10 minute instead of every minute.

The above code, will not delete your past revisions that are already saved in your database. To delete all previous revisions Click >>