• Home
  • DSA
  • Concept
  • Interview
  • Tips&Tricks
  • Tutorial Videos
  • Home
  • DSA
  • Concept
  • Interview
  • Tips&Tricks
  • Tutorial Videos
  • #News
  • #APPS
  • #Events
    • #WWDC
    • #I/O
    • #Ignite
  • #Let’s Talk
  • #Advertise

MyCodeTips mycodetips-newlogocopy1

  • Home
  • DSA
  • Concept
  • Interview
  • Tips&Tricks
  • Tutorial Videos
Programming

Tips to show WordPress Widgets on Condition in Perticular Pages or Area

Tips to show WordPress Widgets on Condition in Perticular Pages or Area

WordPress, by default, provides a set of widgets for showing post categories, tag clouds, search, and calendar. Following WordPress standard themes like TwentyTen and TwentyTwelve, widgets will be shown in all the pages — homepage, post, page, and archive.

But what if we want to display the widgets only in one particular page. Let’s take a look at our options for this.

Different Sidebar File

A WordPress theme requires sidebar.php file to hold the widgets, and uses get_sidebar() template tag to display the widgets on the pages.

We can create multiple customized sidebar files to display in the theme template files.

For example, let’s say we have a Contact page, and we want to have the sidebar in this page to be different from the sidebar of other pages. In this situation, we can create a new sidebar file, and name it something like sidebar-contact.php.

Then, in the contact template file, we can call our new sidebar, this way.
get_sidebar( ‘contact’ );
Everything that is added in the Contact sidebar will be displayed in the Contact page, and won’t be displayed in the other pages. That way that we can display widgets that are more related to the page.

Using Conditional Tags

The above method assumed that you have created a custom template for your page. Alternatively, if you haven’t created one, you can use conditional tags.

Below is an example of code that you can add in page.php; this code will show the Contact sidebar in the contact page, while showing regular sidebars for the other pages.
if ( is_page(‘contact’) ) {
get_sidebar( ‘contact’ );
} else {
get_sidebar();
}

Using Jetpack

Alternatively, you can also do it from the back-end admin with Jetpack. In Jetpack, activate the module called Widget Visibility. With this module, we can hide or show widgets for certain pages.

Go to Appearance > Widgets. You should now find a new button added in the widget named Visibility. Click on the button and set the parameters.

In the above example, I have set a widget that will only show in the Contact page. Apart from Pages, you can also select Categories, Tags, and Posts.

We hope this tip can be useful for you and if you have any question regarding this discussion, feel free to ask in the comment box below.

Liked it? Take a second to support Ranjan on Patreon!
become a patron button
  • Click to share on Reddit (Opens in new window)
  • Click to share on Facebook (Opens in new window)
  • Click to share on Twitter (Opens in new window)
  • Click to share on LinkedIn (Opens in new window)
  • Click to share on Tumblr (Opens in new window)
  • More
  • Click to share on Pocket (Opens in new window)
  • Click to share on Pinterest (Opens in new window)
Written by Ranjan - 1279 Views
Tags | Wordpress
AUTHOR
Ranjan

Namaste, My name is Ranjan, I am a graduate from NIT Rourkela. This website is basically about of what i learnt from my years of experience as a software engineer on software development specifically on mobile application development, design patterns/architectures, its changing scenarios, security, troubleshooting, tools, tips&tricks and many more.

You Might Also Like

mycodetips wordpress

Tips For Every WordPress Developer

December 16, 2013
mycodetips-wordpress-blogger

WordPress vs Blogger – Key Points with Pros and Cons

October 5, 2020
wordpress-coding-blog

Guide To WordPress Coding Standards

October 21, 2022
Next Post
Previous Post

Support us

mycodetips mycodetips
Follow us @ LinkedIn 2850+

Subscribe for updates

Join 8,213 other subscribers

Latest Posts

  • YT-Featured-solidprinciples
    SOLID Principles of Software Design
  • IOS 16 Features
    Latest features in IOS 16
  • r-language
    How can R language be used for data analysis?
  • wordpress-coding-blog
    Guide To WordPress Coding Standards
  • YT-Featured-Algorithm
    What is Algorithm?
  • Frameworks of IOS
    Frameworks of IOS – Part ( I )
  • NSFileManager or NSPathUtilities
    NSFileManager or NSPathUtilities in Objective-C
  • Passing data between view controllers in Objective-C
    Passing data between view controllers in Objective-C
  • structures-classes-enum
    Structures and Classes in swift !
  • control-system-swift
    Control Flow in Swift
whiteboard

Whiteboard(PRO)

whiteboard

Whiteboard(lite)

alphabets

Kids Alphabet

techlynk

Techlynk

techbyte

Do2Day

techbyte

Techbyte

  • #about
  • #myapps
  • #contact
  • #privacy
  • #Advertise
  • #Guestpost
  • #myQuestions

Android Android Studio API APP Programming Apps blogging CSS DATABASE dsa Features HTML HTML5 installation Interview Questions IOS iPhone javascript Mac objective-c OS Programming quicktips SDK SEO SQL swift Tips & Tricks Tools UI Web Wordpress Xcode

  • SOLID Principles of Software Design
  • Latest features in IOS 16
  • How can R language be used for data analysis?
  • Guide To WordPress Coding Standards
  • What is Algorithm?

©mycodetips.com