How To Customize Sidebars In WordPress

By | May 13, 2015

Creating sidebar in a WordPress site is no more a daunting task. The resourceful WordPress repository offers a prolific plugin, named as Widget Logic that facilitates one to create sidebar with a flair.

Widget Logic plugin basically offers a steady control on the sidebar widgets of your WP. Whether you are interested in showcasing certain widgets on an individual page or want it on a few number of pages, this plugin will help you accomplish the task with a breeze. However, due to the included catch, the plugin demands conditional tags for every widget. Therefore, to efficiently use this plugin for creating a sidebar, it is imperative to possess a little knowledge about PHP.

How To Customize Sidebars In WordPress

Customizing sidebars via Widget Logic

Customizing sidebars via Widget Logic

Once you have activated the plugin and added a text widget to the sidebar and created a copy to captivate viewers to invite them download a file, you can refer to the following guide and accomplish the task.

Here is a step-by-step guide for including the content in the sidebar of the About Us page.

• Conditional tag for About Us page
A page ID or page’s slug helps create conditional tags for that page; between slug and ID, you can prefer any one that you like to. If your permalinks are using the post_name slug, the slug for your About Us page will be about-us. By considering this slug, the conditional tag will be is_page(‘about-us’).

• Seek the Widget Logic field in the widget editor
Once the plugin has been activated, the Widget Logic field will appear at the bottom of the editor interface. This will be displayed for all the widgets.

• Insert the conditional tag in the Widget Logic field
As determined in the first step, the conditional tag for About Us page is is_page(‘about-us’). Just, enter this tag into the Widget Logic field.

• Save the changes
Simply, save all the changes that you have made in the widget editor. By doing so, it will display this text widget only on your About Us page.

This was a simple example that represents how to determine a conditional tag and add it in the requisite page via the widget editor. However, if you are interested in customizing a widget on your WordPress blog page, you will need a little different conditional tag. Let’s explore how.

For this, you will need to determine a conditional tag for both the WordPress blog page and single posts.

• For a blog page, the conditional tag will be is_home(). No matter, whether you run your blog with a static front page or a dynamic front page, the conditional tag for a blog will be is_home().

• For single posts, the conditional tag will be is_single(). By default, this tag will include all your posts, thus, there is no need to create a list of all your posts.

• For adding these conditional tags in the Widget Logic field, “||” will be required in between the two conditional tags. Thus, to display a widget on the blog page and on all the posts, one will need to add:

is_home() || is_single()

• Upon saving the modifications, you will get the widget on the blog page and on the pages for all the posts.

The OR condition, which is represented as “||” is used for adding two conditional tags in the Widget Logic field. You can also use the AND condition, which is represented as “&&” to define a particular condition. For instance, if you want to display a widget only on the posts that are tagged with health category. For this, the conditional tags would be

is_single() && in_category(‘health’)

There are numerous conditional tags listed on the Here is a list of some common conditional tags that can be added in the Widget Logic field to customize widgets in WordPress. You can implement a suitable one to customize your WP site in a desired fashion, let’s ponder into the list.

 is_front_page() for home page with a static front page.
 is_home() for blog page (either with a static front page or dynamic front page).
 is_single() for all the pages with blog posts.
 in_category ( ‘category-name’ ) for particular category. This is a great option when a widget is intended for blogs related to a specific category.
 is_page ( ‘page-name’ ) for a particular page on your WP site. The page-name, can refer to the slug associated with that specific page. Moreover, instead of using the slug, you may also choose to use the page ID.

While using the is_page() conditional tag, the selected widget will be displayed on all the pages except the single blog post pages.

Furthermore, in the beginning of a conditional tag, you can also use “!” character. This character will apply your logic to every page other than the pages included in the conditional tag. Let’s consider that you don’t want to display a widget on the About Us page, but need it on all the other pages. This can be done by using the conditional tag as

!is_page ( ‘about-us’)

By thoroughly going through the aforementioned points, you can conveniently customize sidebars in your WordPress website and enhance its usability and visual appeal.

About the Author :

Ava Garcia is an passionate WordPress developer who likes to share her knowledge about latest development in the web technology. She has more than 5 years of experience in the field and is currently working at OSSMedia – a reputed web development company.