• Home
  • Troubleshoot
  • #Example
    • C
    • C++
    • Python
    • R-Programming
  • DSA
  • Quiz
  • Tutorial Videos
  • Home
  • Troubleshoot
  • #Example
    • C
    • C++
    • Python
    • R-Programming
  • DSA
  • Quiz
  • Tutorial Videos
  • #Deals
  • #News
  • #WiKi
  • #APPS
  • #Events
    • #WWDC
    • #I/O
    • #Ignite
  • #Let’s Talk

MyCodeTips mycodetips-newlogocopy1

  • Home
  • Troubleshoot
  • #Example
    • C
    • C++
    • Python
    • R-Programming
  • DSA
  • Quiz
  • 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.

  • 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)
  • Click to share on Pocket (Opens in new window)
  • Click to share on Pinterest (Opens in new window)
Written by Ranjan - 1127 Views
Tags | Wordpress
AUTHOR
Ranjan

I m Ranjan and Sharing my years of experience in Software Development. Love to code in Mobile apps (IOS, Android, Power Apps, Xamarin, Flutter), Machine Learning ( Beginner ), Dot Net, Databases ( SQL Server, MySql, SQLite), WordPress, Cloud Computing ( AWS, Azure, Google, MongoDB) and many more as required on project-specific. Besides this love to travel and cook.

You Might Also Like

mycodetips wordpress

Tips For Every WordPress Developer

December 16, 2013
thumb-wordpress-settings2

WordPress Settings, Some more Configuration

July 11, 2021
thumb wordpress theme new

Few Points before you change WordPress theme

May 24, 2021
Next Post
Previous Post

Subscribe for updates

Join 5,849 other subscribers

whiteboard

Whiteboard(PRO)

whiteboard

Whiteboard(lite)

alphabets

Kids Alphabet

techlynk

Techlynk

techbyte

Do2Day

techbyte

Techbyte

Latest Posts

  • 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
  • swift-concurrency-await
    Concurrency in Swift
  • time-complexity-dsa
    The Term Time Complexity in DSA
  • objective-c-datatypes1
    Objective-C Data Types
  • Convert-jpeg-word
    Convert JPG to Word – Tips You Should Try!
  • objective-c-control-statements2
    Objective-C control statements and loops !

Quick Links

  • #about
  • #myapps
  • #contact
  • #privacy

Other Websites

  • #myQuestions
  • #myBhojanalaya
  • #gadgetFacts
  • #ifscCodesDB

Tag Cloud

Android Android Studio API APP Programming Apps ARC asp.net blogging Browser Config CSS DATABASE DFD error Features GUI HTML HTML5 IDE IIS installation Interview Questions IOS iPhone javascript Mac objective-c OneDrive OS Programming quicktips SDK SEO Settings SMO SQL swift swiftUI Teams Tips & Tricks Tools UI Web Wordpress Xcode

©mycodetips.com