Hide/Show Widgets/Gadgets in Home/post/static/archive pages in Blogger

Once you activate any widget, in your blog, it will be displayed in all the pages by default, including your homepage.But what if you want a certain widget to appear only on a certain page or pages, can it be done? Yes You can do this easily using conditional tags.

first go to Blogger’s Dashboard > Design > Page Elements tab and add a “HTML/JavaScript” gadget. I prefer it because it will be easy for everyone to understand. Give it a unique title so that it does not match with any of the titles of other widgets added.

Go to Dashboard > Design > Edit HTML. Check the Expand Widget Templates check box on top right of the HTML window. Find your widget in the HTML by using Ctrl+F and entering the widget Id in the search box. Let’s say I have given the title for my widget as “Recent Comments”. After searching you will find the below snippets:

<b:widget id='HTML1' locked='false' title='Recent Comments' type='HTML'>
<b:includable id='main'>
<!-- only display title if it's non-empty -->
<b:if cond='data:title != ""'>
<h2 class='title'><data:title/></h2>
</b:if>
<div class='widget-content'>
<data:content/>
</div>

<b:include name='quickedit'/>
</b:includable>
</b:widget>
It's the widget/gadget that you have added from Page Elements tab. All is left is to add conditional tags just below and above to hide the widget form specific pages or posts in Blogger. Let us see some examples:

To show the widget only in HomePage
<b:widget id='HTML1' locked='false' title='Recent Comments' type='HTML'>
<b:includable id='main'>
<b:if cond='data:blog.url == data:blog.homepageUrl'>
<!-- only display title if it's non-empty -->
<b:if cond='data:title != ""'>
<h2 class='title'><data:title/></h2>
</b:if>
<div class='widget-content'>
<data:content/>
</div>

<b:include name='quickedit'/>
</b:if>
</b:includable>
</b:widget>

To Show Blogger Widget in Post Pages only
<b:widget id='HTML1' locked='false' title='Recent Comments' type='HTML'>
<b:includable id='main'>
<b:if cond='data:blog.pageType == "item"'>
<!-- only display title if it's non-empty -->
<b:if cond='data:title != ""'>
<h2 class='title'><data:title/></h2>
</b:if>
<div class='widget-content'>
<data:content/>
</div>

<b:include name='quickedit'/>
</b:if>
</b:includable>
</b:widget>

To show the widget in any particular page
<b:widget id='HTML1' locked='false' title='Recent Comments' type='HTML'>
<b:includable id='main'>
<b:if cond='data:blog.url == "URL of the page"'>
<!-- only display title if it's non-empty -->
<b:if cond='data:title != ""'>
<h2 class='title'><data:title/></h2>
</b:if>
<div class='widget-content'>
<data:content/>
</div>

<b:include name='quickedit'/>
</b:if>
</b:includable>
</b:widget>

To hide a widget only in a particular page
<b:widget id='HTML1' locked='false' title='Recent Comments' type='HTML'>
<b:includable id='main'>
<b:if cond='data:blog.url != "URL of the page"'>
<!-- only display title if it's non-empty -->
<b:if cond='data:title != ""'>
<h2 class='title'><data:title/></h2>
</b:if>
<div class='widget-content'>
<data:content/>
</div>

<b:include name='quickedit'/>
</b:if>
</b:includable>
</b:widget>

To show widgets only in Archive Pages
<b:widget id='HTML1' locked='false' title='Recent Comments' type='HTML'>
<b:includable id='main'>
<b:if cond='data:blog.pageType == "archive"'>
<!-- only display title if it's non-empty -->
<b:if cond='data:title != ""'>
<h2 class='title'><data:title/></h2>
</b:if>
<div class='widget-content'>
<data:content/>
</div>

<b:include name='quickedit'/>
</b:if>
</b:includable>
</b:widget>

To show widgets only in Static Pages
<b:widget id='HTML1' locked='false' title='Recent Comments' type='HTML'>
<b:includable id='main'>
<b:if cond='data:blog.pageType == "static_page"'>
<!-- only display title if it's non-empty -->
<b:if cond='data:title != ""'>
<h2 class='title'><data:title/></h2>
</b:if>
<div class='widget-content'>
<data:content/>
</div>

<b:include name='quickedit'/>
</b:if>
</b:includable>
</b:widget>

To hide widgets in Static Pages
<b:widget id='HTML1' locked='false' title='Recent Comments' type='HTML'>
<b:includable id='main'>
<b:if cond='data:blog.pageType != "static_page"'>
<!-- only display title if it's non-empty -->
<b:if cond='data:title != ""'>
<h2 class='title'><data:title/></h2>
</b:if>
<div class='widget-content'>
<data:content/>
</div>

<b:include name='quickedit'/>
</b:if>
</b:includable>
</b:widget>

The code will check whether the condition is true or false:
  • If the result is true, it executes (and display) the widget’s content.
  • If the result is false, it skips the content and hide the widget.
Click Save Template button and view your blog.
That’s all:)

13 comments so far:

EBA said...

this site gives the clearest instruction. thank you, excellent work.

isohope said...

There is a slight fragment of the widget still showing even though it is hidden. This may be due to my template. Any suggestions?

abikwan said...

thanks for the code. I am really grateful you are here to help us :)

von rod limpot said...

Thanks for sharing.:) Gonna try it.

FAVORAZZI said...

i love all your tips and i keep applying them to my blog, which makes my blog look fantastic.

thanks for sharing

Anonymous said...

nice tips thnx for sharing.

Sandipan said...

Excellent share. I am your fan now.

Danial Abdul Rahim said...

Thanks a lot ^_^

Anonymous said...

Ya good tips ^_^

Anonymous said...

Great work!!!!!!!!!!

Unknown said...

where should I paste the code?

Umer Aslam said...

Thanks for sharing such a nice tutorial.

Anonymous said...

Majestic!

Post a Comment

 
Royal Tutor © 2011 | Privacy Policy | Powered by Blogger | Back to top