How to setup tab completions for WP-CLI commands

WP-CLI is the command line interface for WordPress. If you have not setup WP-CLI yet, see steps to setup WP-CLI.

There is tab completions feature which is generally missed in the installation process. Here are the easy few steps to add tab completions for the WP-CLI. I am using Ubuntu here for example. But it would be similar for UNIX environment.

You need to have bash file for setting up autocomplete in the terminal. WP-CLI has already provided bash file. You can download it from Github repo of WP-CLI.

Put that downloaded wp-completion.bash file under the folder you like. Say you keep under completions in your Home directory.

Now, open your .bashrc file with your favorite text editor.

vi ~/.bashrc

In that file, put code to source your completion file. Syntax will be similar to:

source /FULL/PATH/TO/wp-completion.bash

In our example, it would be:

source /home/nilambar/completions/wp-completion.bash

Save your file and close it. Now you need to source your bashrc file to activate your new code for the terminal.

source ~/.bashrc

Then restart the terminal.

Its that simple, no? But it will be very handy to use WP-CLI. I am sure you will love it.


Custom Logo Implementation in WordPress 4.5

Custom Logo is one of the awesome features of WordPress 4.5. You can see release detail of WordPress 4.5 “Coleman” here. Detail of Custom Logo is here. This link gives you detailed explanation of declaring support for Custom Logo and parameters available.

I needed to update my theme to use Custom Logo. But my all themes has logo option available. Image field was provided in the Customizer for logo. In the implementation of this new feature, existing logo was not supposed to be lost. So, I had to add new update script which will import old logo if set by use in existing theme.

Earlier, logo was displayed like following. Logo was saved in theme mod with key site_logo.


function awesome_logo() {

    $site_logo = get_theme_mod( 'site_logo' );
    if ( ! empty( $site_logo ) ) {
        <a href="<?php echo esc_url( home_url( '/' ) ); ?>">
            <img src="<?php echo esc_url( $site_logo ); ?>" alt="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" />


Update script I used is given below. I have tried to comment each step as much as possible as inline comments.


Making Theme Accessibility Ready in WordPress

Accessibility means access generally. Accessibility in web design means creating web pages that everyone can use, regardless of disability or special needs, use and benefit from everything within their environment.

According to Wikipedia:

Accessibility refers to the design of products, devices, services, or environments for people with disabilities. The concept of accessible design ensures both “direct access” (i.e. unassisted) and “indirect access” meaning compatibility with a person’s assistive technology (for example, computer screen readers).

In WordPress, there is a mission to make WordPress accessible to everyone including the more than one billion humans with disabilities. And regular progress shows that this mission will be achieved in near future.

After hearing so much about Accessibility in WordPress, I wanted to try it in my theme also. So I decided to make my free theme Simple Life accessible. I was new and I did not know anything about making theme accessible. After spending few hours learning about key elements under Accessibility, I started modifying my theme. Honestly speaking, it took some iterations to finally make my theme fully accessible but I learned a lot in the process and I am happy about that. I want to share some points which are important while developing accessible WordPress theme or plugin.


How to add extra menu item in WordPress Navigation menu

WordPress very easy interface for managing navigation for WordPress themes.  But in some cases you may want to add extra menu item in the WordPress navigation. Here is a simple example to show how to add extra menu item in WordPress navigation menu.

function custom_add_login_logout_link( $items, $args  ) {

    if( 'primary' == $args->theme_location ) {
            if ( is_user_logged_in() ) {

                $items .= '<li><a class="btn btn-logout" href="'.wp_logout_url(home_url()).'">Logout</a></li>';

            } else {

                $items .= '<li><a class="btn btn-login" href="'.wp_login_url() .'">Login</a></li>';

        return $items;

add_filter( 'wp_nav_menu_items', 'custom_add_login_logout_link', 10, 2 );

In this example we are targeting primary menu. If you have not registered menu then you have to register nav menu with register_nav_menus function.

register_nav_menus( array(
    'primary' => __( 'Primary Menu' ),  
 ) );